【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 ...
在行级触发器中,不能查询自身表
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> 


目录
相关文章
|
5月前
|
存储
Build desc failed:Fetch table group shards failed on meta proxy:Loading cached shard 1ocation value for table group[dwhg_scm.dwhg_prd_tg_default] failed
Build desc failed:Fetch table group shards failed on meta proxy:Loading cached shard 1ocation value for table group[dwhg_scm.dwhg_prd_tg_default] failed
187 2
|
关系型数据库 MySQL 数据库
[Err] 1143 - SELECT command denied to user 'XX'@'%' for column 'XXX' in table 'XX'
[Err] 1143 - SELECT command denied to user 'XX'@'%' for column 'XXX' in table 'XX'
273 0
[Err] 1143 - SELECT command denied to user 'XX'@'%' for column 'XXX' in table 'XX'
new Grammar in 740 - Internal table group by
Created by Wang, Jerry, last modified on Sep 14, 2015
new Grammar in 740 - Internal table group by
|
SQL
ORA-02292: integrity constraint (xxxx) violated - child record found
在更新表的主键字段或DELETE数据时,如果遇到ORA-02292: integrity constraint (xxxx) violated - child record found 这个是因为主外键关系,下面借助一个小列子来描述一下这个错误: SQL> create table studen...
2359 0
|
SQL 关系型数据库 数据库
ORA-04028: cannot generate diana for object xxx
在ORACLE数据库(10.2.0.5.0)上修改一个包的时候,编译有错误,具体错误信息为"ORA-04028: cannot generate diana for object xxx"。   Warning: Package Body created with compilation errors.
1566 0
|
SQL 关系型数据库
ORA-1652: unable to extend temp segment by 128 in tablespace xxx Troubleshootin
当收到告警信息ORA-01652: unable to extend temp segment by 128 in tablespace xxxx 时,如何Troubleshooting ORA-1652这样的问题呢? 当然一般xxx是临时表空间,也有可能是用户表空间。
2100 0
|
SQL 数据库
SQL logic error or missing database no such table: xxx
原文:SQL logic error or missing database no such table: xxx System.
3353 0