天天看点

table xxxx is mutating, trigger/function may not see it

错误信息:

SQL> update idep_schedule set sched_name='E_终端补贴_add111' where sched_id=15979;

update idep_schedule set sched_name='E_终端补贴_add111' where sched_id=15979

ORA-04091: table IDEP9I.IDEP_SCHEDULE is mutating, trigger/function may not see it

ORA-06512: at "IDEP9I.TRIG_SCHEDULE_UPDATE", line 2

ORA-04088: error during execution of trigger 'IDEP9I.TRIG_SCHEDULE_UPDATE'

[@more@]

出错原因:

1、对于after 类型的 for each row 级别的triggers,都不允许在trigger中访问本trigger所依赖的table

2、对于before 类型的 for each row 级别的triggers,如果使用 insert into ... values 语句触发此trigger ,则在trigger 中访问本table没有问题;

但如果使用 insert into select .. from 语句触发此trigger ,则在trigger 中访问本table就报ora-04091错误;

此规则对于update ,delete同样适用

解决办法1.

PRAGMA AUTONOMOUS_TRANSACTION;

自治事务

解决办法2.

from idep_schedule iss,

改成:

from (select :new.sched_id sched_id, :new.interval interval , :new.state state from dual) iss,

因为无法访问基表,故用select :new.xxx, :new.yyy from dual来构造所需的表。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10896118/viewspace-1054738/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10896118/viewspace-1054738/