【racle】ORA-04091: table xxx is mutating

在行级触发器中,不能查询自身表
YANG@yangdb-rac3> create or replace trigger t_1 
  2  after insert or update on t1
  3  for each row
  4  declare
  5   a number;
  6   begin 
  7  select count(*) into a from t1;
  8  update t_count set count =a;
  9  end t_1;
 10  /
Trigger created.
YANG@yangdb-rac3> insert into t1 values (1,'yangql');
insert into t1 values (1,'yangql')
            *
ERROR at line 1:
ORA-04091: table YANG.T1 is mutating, trigger/function may not see it
ORA-06512: at "YANG.T_1", line 4
ORA-04088: error during execution of trigger 'YANG.T_1'
    在触发器中操作触发此触发器的表,用PRAGMA AUTONOMOUS_TRANSACTION选项,将操作设置为自治事务.
     DECLARE整个块都是属于父事务的,自治事务从离PRAGMA后的第一个BEGIN开始,只要此BEGIN块仍在作用域,则都属于自治事务。例如在DECLARE模块中声明一个写数据库的函数,则此函数虽然在自治事务所在存储过程执行,但其属于父事务;而自治事务中调用的任何函数和存储过程、激发的任何触发器等均为此自治事务的一部分,保持与父事务的隔离。
YANG@yangdb-rac3> create or replace trigger t_1 
  2    after insert or update on t1
  3   for each row
  4   declare
  5     a number; 
  6      pragma autonomous_transaction;
  7    begin
  8     select count(*) into a from t1;
  9     update t_count set count =a;
 10     commit;
 11   end t_1;
 11  /
Trigger created.
YANG@yangdb-rac3> insert into t1 values (1,'yangql');
1 row created.
YANG@yangdb-rac3> 


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

转载于:http://blog.itpub.net/22664653/viewspace-712758/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值