MUTATING ERROR IN TRIGGERS
MUTATING_ERROR:
Either insert or update or delete or select any two operations perform on same table at the same time in trigger,at that time mutating error will be happend.
to avoid this mutating error we can use pragma autonomous_transaction.
examples of mutating error:
example 1 :
here we are deleting the row and at the same time we are selecting(DRL) the record then it leads to mutating error
CREATE OR REPLACE TRIGGER mut_trig
AFTER DELETE ON test
FOR EACH ROW
DECLARE
a VARCHAR2(10);
BEGIN
SELECT name INTO a
FROM test
WHERE id=111;
INSERT INTO test (id,name) VALUES (222,'VOLVO');
DBMS_OUTPUT.PUT_LINE('NAME: '||a);
END mut_trig;
/
Trigger created.
sql>delete from test;
ERROR at line 1:
ORA-04091: table SYSTEM.TEST is mutating, trigger/function may not see it
ORA-06512: at "SYSTEM.MUT_TRIG", line 4
ORA-04088: error during execution of trigger 'SYSTEM.MUT_TRIG'
----------------------------------------------------------------------------------------------------------------
example 2:
here we are deleting the row and at the same time we are updating(DML) the record then it leads to mutating error
CREATE OR REPLACE TRIGGER mutu_trig
AFTER DELETE ON test
FOR EACH ROW
DECLARE
BEGIN
UPDATE test SET name='VOLVO'
WHERE name='HP';
END mutu_trig;
/
Trigger created.
SQL> DELETE FROM test;
DELETE FROM test
*
ERROR at line 1:
ORA-04091: table SYSTEM.TEST is mutating, trigger/function may not see it
ORA-06512: at "SYSTEM.MUTU_TRIG", line 3
ORA-04088: error during execution of trigger 'SYSTEM.MUTU_TRIG'
Gouthami.
-----------------------------------------------------------------------------------------------------
Either insert or update or delete or select any two operations perform on same table at the same time in trigger,at that time mutating error will be happend.
to avoid this mutating error we can use pragma autonomous_transaction.
examples of mutating error:
example 1 :
here we are deleting the row and at the same time we are selecting(DRL) the record then it leads to mutating error
CREATE OR REPLACE TRIGGER mut_trig
AFTER DELETE ON test
FOR EACH ROW
DECLARE
a VARCHAR2(10);
BEGIN
SELECT name INTO a
FROM test
WHERE id=111;
INSERT INTO test (id,name) VALUES (222,'VOLVO');
DBMS_OUTPUT.PUT_LINE('NAME: '||a);
END mut_trig;
/
Trigger created.
sql>delete from test;
ERROR at line 1:
ORA-04091: table SYSTEM.TEST is mutating, trigger/function may not see it
ORA-06512: at "SYSTEM.MUT_TRIG", line 4
ORA-04088: error during execution of trigger 'SYSTEM.MUT_TRIG'
----------------------------------------------------------------------------------------------------------------
example 2:
here we are deleting the row and at the same time we are updating(DML) the record then it leads to mutating error
CREATE OR REPLACE TRIGGER mutu_trig
AFTER DELETE ON test
FOR EACH ROW
DECLARE
BEGIN
UPDATE test SET name='VOLVO'
WHERE name='HP';
END mutu_trig;
/
Trigger created.
SQL> DELETE FROM test;
DELETE FROM test
*
ERROR at line 1:
ORA-04091: table SYSTEM.TEST is mutating, trigger/function may not see it
ORA-06512: at "SYSTEM.MUTU_TRIG", line 3
ORA-04088: error during execution of trigger 'SYSTEM.MUTU_TRIG'
Gouthami.
-----------------------------------------------------------------------------------------------------
Comments
Post a Comment