Triggers and Exceptions
Triggers and Exceptions
DML Triggers are written over the top of a Table, Instead of Triggers are written over the top of
a view.
Q2. What is Mutating Trigger? How to avoid Mutating Trigger Error? How
Compound trigger is useful in avoiding “Mutating Trigger Error”?
Mutating Trigger:: A DML statement that fires a trigger which in turn tries to read or do a write
from the same table then we gets the Mutating Trigger.
Mutating error(ORA-04091) occurs whenever a row level trigger tries to modify or select data
from the table that is already undergoing change. Mutating error get raised from row level trigger
only, and not statement level trigger.
“ORA-04091: table emp_t is mutating, trigger/function may not see it.”
BEGIN
SELECT sal INTO lv_ceo_sal
FROM emp_t
WHERE job='CEO' AND deptno=:new.deptno; /* Reason for Mutating Error*/
Solution 1:
By creating Statement Level Trigger to get the value and that value can be stored in a
package where variable is defined i.e by Global Variable.
BEGIN
Solution2
Using Compound Trigger