开发者

Triggers: how can I initialize the value on a table with a value on another?

开发者 https://www.devze.com 2023-02-05 11:53 出处:网络
I\'m creating a trigger to initialize the value plaz开发者_如何学Pythonas_disponibles on table VUELO with the value capacidad on table MODELO. Like this:

I'm creating a trigger to initialize the value plaz开发者_如何学Pythonas_disponibles on table VUELO with the value capacidad on table MODELO. Like this:

create or replace
TRIGGER inicializar_plazas_disponibles
    BEFORE INSERT OR UPDATE ON VUELO 
    BEGIN
         SET VUELO (plazas_disponibles) = MODELO (capacidad);
    END inicializar_plazas_disponibles; 

And I'm getting the following errors:

Error(2,10): PL/SQL: SQL Statement ignored
Error(2,14): PL/SQL: ORA-00922: missing or invalid option
Error(2,23): PL/SQL: ORA-00971: missing SET keyword

Why?


Because that isn't how you change a value in the row being inserted - you need to modify it using the :NEW syntax (documentation); and you haven't shown how to retrieve a relevant value from the MODELO table.

You need to do something like:

CREATE OR REPLACE TRIGGER inicializar_plazas_disponibles
BEFORE INSERT OR UPDATE ON vuelo
FOR EACH ROW
BEGIN
    SELECT capacidad
    INTO :NEW.plazas_disponibles
    FROM modelo
    WHERE ... some condition, presumably another :NEW column ...
END;

(Although I'm not entirely sure whether you can select straight into a :NEW value - try that, but if not you'll need to declare a variable of the same type, select into that instead, and then assign that to the :NEW).

0

精彩评论

暂无评论...
验证码 换一张
取 消