Home > Database > Mysql Tutorial > Oracle触发器中增删改查本表

Oracle触发器中增删改查本表

WBOY
Release: 2016-06-07 17:30:50
Original
1575 people have browsed it

Oracle触发器中增删改查本表 (1)只有before insert触发器中才可以查询或更新本表 create or replace trigger tri_test_ins befor

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触发器的使用

Oracle触发器给表自身的字段重新赋值出现ORA-04091异常

Oracle创建触发器调用含参数存储过程

Oracle触发器查询统计本表

MySQL 触发器应用案例

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template