I'm creating a trigger to initialize the value plazas_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
).