Oracle触发器中增删改查本表
(1)只有before insert触发器中才可以查询或更新本表
create or replace trigger tri_test_ins
before insert
on test
for each row
declare
v_cnt integer;
begin
select count(*) into v_cnt from test;
dbms_output.put_line('test count:'||to_char(v_cnt));
update test set a9='99';
end;
执行insert后,只有当前插入的记录值不是99,其它的记录都被更新成了99。
(2)before/after update、before/after delete、after insert5种情况都不可以查询或更新本表。
(3)使用自治事务可以实现任意触发器查本表。但不能实现在自治事务中更新本表。
查询本表的情况是最常见的。
create or replace trigger tri_test_ins
after update
on test
for each row
declare
v_cnt integer;
PRAGMA AUTONOMOUS_TRANSACTION;
begin
begin
select count(*) into v_cnt from test;
dbms_output.put_line('test count:'||to_char(v_cnt));
end;
end;
(4)使用自治事务可以实现新增或删除本表的记录。这种情况一般不会用到。
相关阅读:
Oracle触发器的使用 http://www.linuxidc.com/Linux/2013-03/81396.htm
Oracle触发器给表自身的字段重新赋值出现ORA-04091异常 http://www.linuxidc.com/Linux/2013-07/87075.htm
Oracle创建触发器调用含参数存储过程 http://www.linuxidc.com/Linux/2013-02/80018.htm
Oracle触发器查询统计本表 http://www.linuxidc.com/Linux/2013-01/77671.htm
MySQL 触发器应用案例 http://www.linuxidc.com/Linux/2013-02/79861.htm
更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12
