Oracle DB触发器错误如何解决?
How to solve the Oracle DB trigger error?
我编写了一个数据库触发器来监视插入操作。插入一条新记录后,我想自动将 CREATION_DATE
设置为 sysdate
。
我想插入一条新记录时出错:
error
ORA-04091: table REPORT is mutating, trigger/function may not
see it
ORA-06512: at "CREATION_DATE_TEST", line 2
ORA-04088: error during execution of trigger 'CREATION_DATE_TEST'
我的代码:
CREATE OR REPLACE TRIGGER creation_date_test
AFTER INSERT ON REPORT FOR EACH ROW
BEGIN
UPDATE REPORT set CREATION_DATE = sysdate
WHERE ROWID = :new.ROWID;
END;
我也试过用PROJECT_ID = new.PROJECT_ID
替换ROWID = :new.ROWID
。它抛出同样的错误。
听起来您只需要一个插入前触发器来设置 :new.creation_date
create or replace trigger creation_date_test
before insert on report
for each row
begin
:new.creation_date := sysdate;
end;
我编写了一个数据库触发器来监视插入操作。插入一条新记录后,我想自动将 CREATION_DATE
设置为 sysdate
。
我想插入一条新记录时出错:
error
ORA-04091: table REPORT is mutating, trigger/function may not see it
ORA-06512: at "CREATION_DATE_TEST", line 2
ORA-04088: error during execution of trigger 'CREATION_DATE_TEST'
我的代码:
CREATE OR REPLACE TRIGGER creation_date_test
AFTER INSERT ON REPORT FOR EACH ROW
BEGIN
UPDATE REPORT set CREATION_DATE = sysdate
WHERE ROWID = :new.ROWID;
END;
我也试过用PROJECT_ID = new.PROJECT_ID
替换ROWID = :new.ROWID
。它抛出同样的错误。
听起来您只需要一个插入前触发器来设置 :new.creation_date
create or replace trigger creation_date_test
before insert on report
for each row
begin
:new.creation_date := sysdate;
end;