[原創] 有關觸發器 ORA-04091解決方法

yxyup發表於2009-05-26

YXYUP@dbatest>create table t_trigger(f1 number,f2 number,f3 number);

Table created.

YXYUP@dbatest>create or replace trigger test_trigger
  2    after update of f2 on t_trigger
  3    for each row
  4  BEGIN
  5    update t_trigger
  6       set f3 = 0
  7     where f1 = :new.f1 ;
  8  END;
  9  /

Trigger created.

Elapsed: 00:00:00.16

YXYUP@dbatest>
YXYUP@dbatest>insert into t_trigger values(1,1,1);

1 row created.

Elapsed: 00:00:00.01
YXYUP@dbatest>commit;

Commit complete.

Elapsed: 00:00:00.01
YXYUP@dbatest>select * from t_trigger;

        F1         F2         F3
---------- ---------- ----------
         1          1          1

Elapsed: 00:00:00.02
YXYUP@dbatest>
YXYUP@dbatest>
YXYUP@dbatest>update t_trigger set f2=0;
update t_trigger set f2=0
       *
ERROR at line 1:
ORA-04091: table YXYUP.T_TRIGGER is mutating, trigger/function may not see it
ORA-06512: at "YXYUP.TEST_TRIGGER", line 2
ORA-04088: error during execution of trigger 'YXYUP.TEST_TRIGGER'



YXYUP@dbatest>create or replace trigger test_trigger
  2    after update of f2 on t_trigger
  3    for each row
  4  BEGIN
  5     :new.f3:=0;  
  6  END;
  7  /
create or replace trigger test_trigger
                          *
ERROR at line 1:
ORA-04084: cannot change NEW values for this trigger type

YXYUP@dbatest>select * from t_trigger;

        F1         F2         F3
---------- ---------- ----------
         1          1          1

Elapsed: 00:00:00.01

YXYUP@dbatest>create or replace trigger test_trigger
  2    after update of f2 on t_trigger
  3    for each row
  4  BEGIN
  5     :new.f3:=0;  
  6  END;
  7  /
create or replace trigger test_trigger
                          *
ERROR at line 1:
ORA-04084: cannot change NEW values for this trigger type

YXYUP@dbatest>
YXYUP@dbatest>create or replace trigger test_trigger
  2    before update of f2 on t_trigger
  3    for each row
  4  BEGIN
  5     :new.f3 :=0;  
  6  END;
  7  /

Trigger created.

Elapsed: 00:00:00.04
YXYUP@dbatest>select * from t_trigger;

        F1         F2         F3
---------- ---------- ----------
         1          1          1

Elapsed: 00:00:00.01
YXYUP@dbatest>update t_trigger set f2=0;

1 row updated.

Elapsed: 00:00:00.00
YXYUP@dbatest>commit;

Commit complete.

Elapsed: 00:00:00.01
YXYUP@dbatest>select * from t_trigger;

        F1         F2         F3
---------- ---------- ----------
         1          0          0

Elapsed: 00:00:00.00
YXYUP@dbatest>

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7364032/viewspace-604230/,如需轉載,請註明出處,否則將追究法律責任。

相關文章