0

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.

1 Answer 1

3

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;
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks so much! Your answer really helpful!!
@deli - Is creation_date a varchar2 rather than a date as the name would imply? I wouldn't expect there to be any strings used in the code I posted.
I have changed the data type now. Thanks !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.