我正在尝试编写一个触发器,如下例所示:

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;
)

失败了!
只有这样才能工作:
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);
)

我做错什么了?

最佳答案

我认为应该用if-then逻辑编写一个存储过程,并从这个触发器调用它。我认为触发器只支持简单的sql语句,而不支持spl语句
编辑:

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);

10-05 22:51
查看更多