I am trying to write a trigger like in the following simplified example:
x
create trigger adr_trg update of fname, lname on adr
REFERENCING OLD AS o NEW AS n
FOR EACH ROW
(
IF o.fname <> n.fname THEN
insert into adrlog (old_value, new_value)
values (o.fname, n.fname);
END IF;
IF o.lname <> n.lname THEN
insert into adrlog (old_value, new_value)
values (o.lname, n.lname);
END IF;
)
This fails!
Only this works:
create trigger adr_trg update of fname, lname on adr
REFERENCING OLD AS o NEW AS n
FOR EACH ROW
(
insert into adrlog (old_value, new_value)
values (o.fname, n.fname);
)
What am I doing wrong?
Advertisement
Answer
I think you should write a stored procedure with the IF – THEN logic and call that from this trigger. I think triggers support only simple SQL statements, not SPL statements
edit:
CREATE PROCEDURE proc1()
REFERENCING OLD AS o NEW AS n FOR tab1;
your logic .
CREATE TRIGGER adr_trg update of fname, lname on adr
REFERENCING OLD AS o NEW AS n
FOR EACH ROW(EXECUTE PROCEDURE proc1() WITH TRIGGER REFERENCES);