Reputation: 922
I wrote a DB trigger to monitor an insert action. After inserting a new record, I would like to automatically set the CREATION_DATE
to sysdate
.
I get an error when I want to insert a new record:
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'
My code:
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;
I also tried to replace ROWID = :new.ROWID
with PROJECT_ID = new.PROJECT_ID
. It throws the same error.
Upvotes: 0
Views: 551
Reputation: 231651
It sounds like you just want a before insert trigger that sets the :new.creation_date
create or replace trigger creation_date_test
before insert on report
for each row
begin
:new.creation_date := sysdate;
end;
Upvotes: 3