触发器的四种应用场景
触发器语法
CREATE [OR REPLACE] TRIGGER 触发器名称 {BEFORE|AFTER} {DELETE|INSERT|UPDATE[OF 列名]} ON 表名 [FOR EACH ROW [WHEN(条件)]] PLSQL块
触发器分类
- 行级触发器
行级触发器作用的每一条记录,都会被触发,在行级触发器上使用:old和:new伪记录变量识别值的状态
- 语句级触发器
在指定的操作之前或者操作之后执行一次,不管这条语句影响了多少行,只执行一次。
场景一:实施复杂的安全性检查
![](http://upload-images.jianshu.io/upload_images/437049-94baeba0622556a4.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
1.pic.jpg
场景二:数据确认
![](http://upload-images.jianshu.io/upload_images/437049-4b7490596d1e968b.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
2.pic.jpg
场景三:数据的审计
![](http://upload-images.jianshu.io/upload_images/437049-c793a8688af0d345.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
3.pic.jpg
场景四:数据库的备份和同步
![](http://upload-images.jianshu.io/upload_images/437049-1ad896848064a101.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4.pic.jpg
![](http://upload-images.jianshu.io/upload_images/437049-1ad896848064a101.jpg?imageMogr2/auto-orient/strip%7CimageView2/2)
![](http://upload-images.jianshu.io/upload_images/437049-c793a8688af0d345.jpg?imageMogr2/auto-orient/strip%7CimageView2/2)
![](http://upload-images.jianshu.io/upload_images/437049-4b7490596d1e968b.jpg?imageMogr2/auto-orient/strip%7CimageView2/2)
![](http://upload-images.jianshu.io/upload_images/437049-94baeba0622556a4.jpg?imageMogr2/auto-orient/strip%7CimageView2/2)
最怕你一生碌碌无为 还安慰自己平凡可贵