PLSQL触发器随笔
- 触发器
触发器在数据库里以独立的对象存储,它与存储过程不同的是,存储过程通过其它程序来启动运行或直接启动运行,
而触发器是由一个事件来启动运行。即触发器是当某个事件发生时自动地隐式运行。
并且,触发器不能接收参数。所以运行触发器就叫触发或点火(firing)。
ORACLE事件指的是对数据库的表进行的INSERT、UPDATE及DELETE操作或对视图进行类似的操作。
ORACLE将触发器的功能扩展到了触发ORACLE,如数据库的启动与关闭等。
create or replace trigger del_emp2 before update or delete or insert on emp111 --在增删改前触发 referencing new as nn old as oo --新数据写入nn 旧的写入oo for each row when (nn.sal > 2000) --在新写入的sal>2000时触发 begin if INSERTING then dbms_output.put_line('the operation is insert'); elsif UPDATING then dbms_output.put_line('the operation is update'); elsif DELETING then dbms_output.put_line('the operation is delete'); else dbms_output.put_line('others operation'); end if; end;
——输出1
update emp111 set sal = 2500 where ename = 'KING' --在执行满足条件的操作时 --输出 --the operation is update
——输出2
update emp111 set sal = 1900 where ename = 'KING' --条件不满足,没有输出
posted on 2017-08-01 19:05 string9527 阅读(240) 评论(0) 编辑 收藏 举报