Oracle 11g Compound Trigger
In Oracle 11g, the concept of compound trigger was introduced. A compound trigger is a single trigger on a table that enables you to specify actions for each of four timing points:
- Before the firing statement
- Before each row that the firing statement affects
- After each row that the firing statement affects
- After the firing statement
With the compound trigger, both the statement-level and row-level action can be put up in a single trigger. Plus there is an added advantage: it allows sharing of common state between all the trigger-points using variable. This is because compound trigger in oracle 11g has a declarative section where one can declare variable to be used within trigger. This common state is established at the start of triggering statement and is destroyed after completion of trigger (regardless of trigger being in error or not). If same had to be done without compound-trigger, it might have been required to share data using packages.
When to use Compound Triggers
The compound trigger is useful when you want to accumulate facts that characterize the “for each row” changes and then act on them as a body at “after statement” time. Two popular reasons to use compound trigger are:
- To accumulate rows for bulk-insertion. We will later see an example for this.
- To avoid the infamous ORA-04091: mutating-table error.
Details of Syntax
CREATE OR REPLACE TRIGGER compound_trigger_name
FOR [INSERT|DELETE]UPDATE [OF column] ON table
COMPOUND TRIGGER
-- Declarative Section (optional)
-- Variables declared here have firing-statement duration. --Executed before DML statement
BEFORE STATEMENT IS
BEGIN
NULL;
END BEFORE STATEMENT; --Executed before each row change- :NEW, :OLD are available
BEFORE EACH ROW IS
BEGIN
NULL;
END BEFORE EACH ROW; --Executed aftereach row change- :NEW, :OLD are available
AFTER EACH ROW IS
BEGIN
NULL;
END AFTER EACH ROW; --Executed after DML statement
AFTER STATEMENT IS
BEGIN
NULL;
END AFTER STATEMENT; END compound_trigger_name;
Note the ‘COMPOUND TRIGGER’ keyword above.
Some Restriction/Catches to note
- The body of a compound trigger must be a compound trigger block.
- A compound trigger must be a DML trigger.
- A compound trigger must be defined on either a table or a view.
- The declarative part cannot include PRAGMA AUTONOMOUS_TRANSACTION.
- A compound trigger body cannot have an initialization block; therefore, it cannot have an exception section. This is not a problem, because the BEFORE STATEMENT section always executes exactly once before any other timing-point section executes.
- An exception that occurs in one section must be handled in that section. It cannot transfer control to another section.
- If a section includes a GOTO statement, the target of the GOTO statement must be in the same section.
- OLD, :NEW, and :PARENT cannot appear in the declarative part, the BEFORE STATEMENT section, or the AFTER STATEMENT section.
- Only the BEFORE EACH ROW section can change the value of :NEW.
- If, after the compound trigger fires, the triggering statement rolls back due to a DML exception:
- Local variables declared in the compound trigger sections are re-initialized, and any values computed thus far are lost.
- Side effects from firing the compound trigger are not rolled back.
- The firing order of compound triggers is not guaranteed. Their firing can be interleaved with the firing of simple triggers.
- If compound triggers are ordered using the FOLLOWS option, and if the target of FOLLOWS does not contain the corresponding section as source code, the ordering is ignored.
Oracle 11g Compound Trigger的更多相关文章
- PowerDesginer 生成的Oracle 11g 组合触发器代码编译错误(29): PLS-00103
问题描述: 采用PowerDesigner15针对Oracle 11g 创建物理数据模型,想实现一个字段的自增,采用如下步骤: 1.创建序列,命名为Sequence_1; 2.在自增字段编辑窗口中,选 ...
- Oracle 11g新特性
文章转自网络 Oracle 11g于2007年7月11日美国东部时间11时(北京时间11日22时)正式发布,11g是甲骨文公司30年来发布的最重要的数据库版本,根据用户的需求实现了信息生命周期管理(I ...
- SQL SERVER 2008向ORACLE 11G迁移示例
来源于:http://www.cnblogs.com/hiizsk/ 由SQL SERVER 2008向ORACLE 11G迁移过程记录之一-表 使用Oracle Sql Developer将SQL ...
- Zero Downtime Upgrade of Oracle 10g to Oracle 11g Using GoldenGate — 3
DDL Setup Steps SQL> grant execute on utl_file to ggs; Grant succeeded. Create GLOBALS file [orac ...
- oracle 11g使用deferred_segment_creation 延迟段创建特性时遇到的问题总结
总结,下面是两个问题.问题1是用户可以在所有表空间创建表;问题2是exp不能导出空表 问题1: 版本:oracle 11.2.0.1.0 select * from v$version; 创建用户aa ...
- ORACLE 11G R2 RAC classical install OGG12.1(LINUX) 经典抽取模式单项同步配置OGG12.1
博文结构图如下: 一.环境描述以及注意事项 1.1 环境简介 IP 系统 Oracle版本 OGG版本 源端 172.16.10.16/36 RHEL6.5 oracle11204 12.1 目标端 ...
- Oracle 11g Articles
发现一个比较有意思的网站,http://www.oracle-base.com/articles/11g/articles-11g.php Oracle 11g Articles Oracle Dat ...
- Oracle 11g R2性能优化 SQL TRACE
作为Oracle官方自带的一种基本性能诊断工具,SQL Trace可以用来评估当前正在运行的SQL语句的效率,同时为该语句生成统计信息等,并保存这些信息到指定路径下的跟踪文件(trace)当中.SQL ...
- Oracle 11g trace events
oracle的events,是我们在做自己的软件系统时可以借鉴的 Oracle 11g trace eventsORA-10001: control file crash event1ORA-1000 ...
随机推荐
- hdu6354 Everything Has Changed (圆的相交弧长)
题目传送门 题意: 用一堆圆来切割一个圆心为原点,半径为R的圆A,问切割完毕后圆A外围剩余部分的周长(图中的红线部分). 思路: 首先判定圆与圆A的关系,这题我们只需要与A内切.相交的圆. 然后就是求 ...
- rk3288 android5.1 修改时区
/work/rk3288/firefly-rk3288_android5.1_git_20180126/device/rockchip/rk3288/rk3288_box/system.prop 修改 ...
- 一、AJAX
一. (function ($) { //1.得到$.ajax的对象 var _ajax = $.ajax; $.ajax = function (options) { //2.每次调用发送ajax请 ...
- NotePad++安装 html.css.js智能提示【转】
https://www.cnblogs.com/alirong/archive/2012/04/12/2443971.html
- spring boot 提纲
http://tengj.top/categories/Spring-Boot%E5%B9%B2%E8%B4%A7%E7%B3%BB%E5%88%97/ http://blog.csdn.net/ca ...
- windows H2database 安装
转载百度经验 H2是一个开源的.纯java实现的关系数据库,小巧并且使用方便,十分适合作为嵌入式数据库使用 首先打开浏览器进入H2官网http://www.h2database.com/html/ma ...
- 如何开启spring框架以注解形式的配置
步骤 导包(新版本需要导入spring-aop-4.3.17.RELEASE.jar) 为配置文件applicationContext.xml引入新的命名空间(约束) 开启使用注解 <?xml ...
- Scene Text Detection(场景文本检测)论文思路总结
任意角度的场景文本检测论文思路总结共同点:重新添加分支的创新更突出场景文本检测基于分割的检测方法 spcnet(mask_rcnn+tcm+rescore) psenet(渐进扩展) mask tex ...
- 人生苦短_我用Python_类与对象的概念_006
Python类与对象的概念类和对象--->万事万物都对象物以类聚.人以群分 --->?划分标准性别分 男女 中性成绩分 优秀 良好 不及格 类->根据类的属性来划分类的实例-> ...
- Ubuntu查找软件命令
查找软件: apt-cache search <your search item>