ITPub博客

首页 > 数据库 > Oracle > table xxxx is mutating, trigger/function may not see it

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

原创 Oracle 作者:jayklx 时间:2011-08-12 22:49:26 0 删除 编辑

错误信息:

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博客 ” ,链接:https://blog.itpub.net/10896118/viewspace-1054738/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2010-12-26

  • 博文量
    15
  • 访问量
    17964