语句级别,行级别前都可以读或修改触发语句的任何变异表 ? 大哥 我这么没搞懂是怎么回事呢 1 create or replace trigger t_t 2 before insert or update on t 3 for each row 4 declare 5 nn number; 6 begin 7 select count(*) into nn from t; 8 dbms_output.put_line(nn); 9* end; SQL> /触发器已创建SQL> select * from t; N ---------- 1SQL> insert into t values(2); //// this is ok 1已创建 1 行。SQL> commit;提交完成。SQL> update t set n=3 where n=1; update t set n=3 where n=1 * ERROR 位于第 1 行: ORA-04091: 表 LGONE.T 发生了变化,触发器/函数不能读 ORA-06512: 在"LGONE.T_T", line 4 ORA-04088: 触发器 'LGONE.T_T' 执行过程中出错如果INSERT语句只影响一行的话,则在该行的之前和之后触发器将不把触发表 作为变异表对待,这是在行级触发器可能载入或修改触发表时的唯一案例。
sorry,没有讲清楚 可对:new.colname这样数据可以修改,即对于当前触发表所触发的行数据可以修改它。 对于:old.colname永远只能只读 SQL> create table bb (id varchar2(10));Table createdSQL> SQL> create or replace trigger t_t 2 before insert or update on bb 3 for each row 4 declare 5 nn number; 6 begin 7 select count(*) into nn from bb; 8 dbms_output.put_line(nn); 9 end; 10 /Trigger createdSQL> select * from bb;ID ----------SQL> insert into bb values('1');1 row insertedSQL> select * from bb;ID ---------- 1
create or replace trigger t_t 2 before insert or update on bb 3 for each row 4 declare 5 nn number; 6 begin 7 select count(*) into nn from bb; 8 dbms_output.put_line(nn); 9 end;
由于该触发器是创建在sys模式下的 因此,这段程序中的select count(*) into nn from bb;能够成功执行, 但我要说的是如果上面的触发器是创建在非sys模式下时 此触发器在被触发时就会报错,因为他执行了变异表所不允许的 操作语句select count(*) into nn from bb; 这到底是为什么?
在一个pl*sql中,select count(*) from ... 的瞬间将启动表级锁。 与UPDATE的行锁有冲突。
为什么创建在sys下的行级触发器没有以下两个限制?
触发器体中的 SQL 语句不能进行下列操作:
读或修改触发语句的任何变异表,其中包括触发表本身。
读或修改触发表的约束表中的主关键字,唯一关键字和外部关键字列。除此之外的其他列可以修改。
大哥 我这么没搞懂是怎么回事呢 1 create or replace trigger t_t
2 before insert or update on t
3 for each row
4 declare
5 nn number;
6 begin
7 select count(*) into nn from t;
8 dbms_output.put_line(nn);
9* end;
SQL> /触发器已创建SQL> select * from t; N
----------
1SQL> insert into t values(2); //// this is ok
1已创建 1 行。SQL> commit;提交完成。SQL> update t set n=3 where n=1;
update t set n=3 where n=1
*
ERROR 位于第 1 行:
ORA-04091: 表 LGONE.T 发生了变化,触发器/函数不能读
ORA-06512: 在"LGONE.T_T", line 4
ORA-04088: 触发器 'LGONE.T_T' 执行过程中出错如果INSERT语句只影响一行的话,则在该行的之前和之后触发器将不把触发表
作为变异表对待,这是在行级触发器可能载入或修改触发表时的唯一案例。
可对:new.colname这样数据可以修改,即对于当前触发表所触发的行数据可以修改它。
对于:old.colname永远只能只读
SQL> create table bb (id varchar2(10));Table createdSQL>
SQL> create or replace trigger t_t
2 before insert or update on bb
3 for each row
4 declare
5 nn number;
6 begin
7 select count(*) into nn from bb;
8 dbms_output.put_line(nn);
9 end;
10 /Trigger createdSQL> select * from bb;ID
----------SQL> insert into bb values('1');1 row insertedSQL> select * from bb;ID
----------
1
2 before insert or update on bb
3 for each row
4 declare
5 nn number;
6 begin
7 select count(*) into nn from bb;
8 dbms_output.put_line(nn);
9 end;
由于该触发器是创建在sys模式下的
因此,这段程序中的select count(*) into nn from bb;能够成功执行,
但我要说的是如果上面的触发器是创建在非sys模式下时
此触发器在被触发时就会报错,因为他执行了变异表所不允许的
操作语句select count(*) into nn from bb;
这到底是为什么?
与UPDATE的行锁有冲突。