Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Mutating table inside trigger
Hi!
I have a before insert,update,delete trigger which put records inside a log table (this works OK). Now I have to add some more functionality to this trigger. I do this before I add the log record to the logpost.
The insert is OK but I'm getting table is mutating and trigger may not see it error.
I have omitted some part to at least show you the ide. Oracle 9i is used.
CREATE OR REPLACE TRIGGER MY_TRIGGER_TR BEFORE
INSERT OR DELETE OR UPDATE
ON MY_TABLE REFERENCING OLD AS OLDREC NEW AS NEWREC FOR EACH ROW
DECLARE
---some variables here
IF INSERTING THEN
IF (:newREC.IDCODKAT ='kat.001') THEN
--Update RecordB,RecordC,RecordD using :newREC values
end IF;
--Do insert into log tables which I always do no matter value of
:newREC.IDCODKAT
end if;
IF DELETING THEN
IF (:oldREC.IDCODKAT ='kat.001') THEN
--Delete RecordB,RecordC,RecordD using :oldREC values
end IF;
--Do insert into log tables which I always do no matter value of
:oldREC.IDCODKAT
END IF;
END;
I can get it to work if I follow the steps
http://osi.oracle.com/~tkyte/Mutate/index.html
1. Creating a package that defines an array where I can store rowids. 2. A before trigger which "reset" the array 3. An after row level trigger which saves the rowid into the array 4. An efter trigger that loops the array and perform the action
but this seems to be like hunting ants with a elephant gun. Isn't there an easier solution (in Oracle9i)?
Regards
/Hans Börjesson
Received on Fri Mar 07 2003 - 05:43:13 CST
![]() |
![]() |