zoukankan      html  css  js  c++  java
  • ORA-04091: table xxx is mutating, trigger/function may not see it

    Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 
    Connected as tbcs
     
    SQL> 
    SQL> 
    SQL> drop trigger tbcs.TRG_CJW_TEST;
     
    drop trigger tbcs.TRG_CJW_TEST
     
    ORA-04080: trigger 'TRG_CJW_TEST' does not exist
    SQL> drop table tbcs.cjw_test;
     
    drop table tbcs.cjw_test
     
    ORA-00942: table or view does not exist
    SQL> create table cjw_test
      2  (
      3  itemid1    varchar2(10),
      4  itemid2    varchar2(10),
      5  itemid3    varchar2(10)
      6  );
     
    Table created
    SQL> insert into cjw_test values('1','1','1');
     
    1 row inserted
    SQL> commit;
     
    Commit complete
    
    /*
    对于after 类型的 for each row 级别的triggers,不论哪种insert语句触发了trigger,
    都不允许在 trigger 中访问本trigger所依赖的table的
    */
    
    SQL> create or replace trigger trg_cjw_test
      2    after insert on tbcs.cjw_test
      3    for each row
      4  declare
      5    i   number:=0;
      6  begin
      7    select count(1) into i from tbcs.cjw_test;
      8  end trg_cjw_test;
      9  /
     
    Trigger created
     
    SQL> insert into cjw_test values('1','1','1');
     
    insert into cjw_test values('1','1','1')
     
    ORA-04091: table TBCS.CJW_TEST is mutating, trigger/function may not see it
    ORA-06512: at "TBCS.TRG_CJW_TEST", line 4
    ORA-04088: error during execution of trigger 'TBCS.TRG_CJW_TEST'
     
    SQL> 
    SQL> 
    /*
    对于before 类型的 for each row 级别的triggers,如果使用 insert into ... values 语句触发此trigger ,
    则在trigger 中访问本table没有问题;但如果使用 insert into select .. from 语句触发此trigger ,
    则在trigger 中访问本table就报ora-04091错误;
    */
    
    SQL> create or replace trigger trg_cjw_test
      2    before insert on tbcs.cjw_test
      3    for each row
      4  declare
      5    i   number:=0;
      6  begin
      7    select count(1) into i from tbcs.cjw_test;
      8  end trg_cjw_test;
      9  /
     
    Trigger created
     
    SQL> insert into cjw_test values('1','1','1');
     
    1 row inserted
     
    SQL> commit;
     
    Commit complete
     
    SQL> 
    SQL> create or replace trigger trg_cjw_test
      2    before insert on tbcs.cjw_test
      3    for each row
      4  declare
      5    i   number:=0;
      6  begin
      7    insert into tbcs.cjw_test
      8    select '2','2','2' from dual;
      9  end trg_cjw_test;
     10  /
     
    Trigger created
     
    SQL> insert into cjw_test values('1','1','1');
     
    insert into cjw_test values('1','1','1')
     
    ORA-04091: table TBCS.CJW_TEST is mutating, trigger/function may not see it
    ORA-06512: at "TBCS.TRG_CJW_TEST", line 4
    ORA-04088: error during execution of trigger 'TBCS.TRG_CJW_TEST'
    ORA-06512: at "TBCS.TRG_CJW_TEST", line 4
    ORA-04088: error during execution of trigger 'TBCS.TRG_CJW_TEST'
     
    SQL> 
    
     SQL> 
    /*
    上面实验中使用before,我们在仅插入一条数据的情况下,并没有报错,现在试一下插入多条数据的情况
    */
    SQL> create or replace trigger trg_cjw_test
      2    before insert on tbcs.cjw_test
      3    for each row
      4  declare
      5    i   number:=0;
      6  begin
      7    select count(1) into i from tbcs.cjw_test;
      8  end trg_cjw_test;
      9  /
     
    Trigger created
     
    SQL> 
    SQL> create table cjw_test_bak as select * from cjw_test;
     
    Table created
    SQL> insert into cjw_test_bak values('2','1','1');
     
    1 row inserted
    SQL> insert into cjw_test_bak values('3','1','1');
     
    1 row inserted
    SQL> insert into cjw_test_bak values('4','1','1');
     
    1 row inserted
     
    SQL> commit;
     
    Commit complete
     
    SQL> insert into cjw_test select * from cjw_test_bak;
     
    insert into cjw_test select * from cjw_test_bak
     
    ORA-04091: table TBCS.CJW_TEST is mutating, trigger/function may not see it
    ORA-06512: at "TBCS.TRG_CJW_TEST", line 4
    ORA-04088: error during execution of trigger 'TBCS.TRG_CJW_TEST'
     
    SQL> 
  • 相关阅读:
    ping 的零碎知识
    dhcp问题
    Apache相关知识与配置
    Android || IOS录制mp3语音文件方法
    Sheet can not be presented because the view is not in a window的解决办法,和window的简单使用
    测试题1 IOS面试基础题
    IOS 封装类的时候注释格式,使用的时候可以想官方库一样快捷显示
    IOS 用正则表达式解析HTML等文件,得到所有文本
    IOS源码封装成.bundle和.a文件时,使用单例作为出口的写法!任何封装都建议使用这种方法作为出口
    XMLParser解析xml--内容源自网络(在静态库中不能用GDATA来解析,因为静态库不能加动态库)
  • 原文地址:https://www.cnblogs.com/dingyingsi/p/3358675.html
Copyright © 2011-2022 走看看