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 ...
随机推荐
- An easy problem (位运算)
[题目描述] 给出一个整数,输出比其大的第一个数,要求输出的数二进制表示和原数二进制表示下1的个数相同. [题目链接] http://noi.openjudge.cn/ch0406/1455/ [算法 ...
- 牛客练习赛27-----C.水图(DFS求最长路径)
传送门 来源:牛客网题目描述:小w不会离散数学,所以她van的图论游戏是送分的小w有一张n个点n-1条边的无向联通图,每个点编号为1~n,每条边都有一个长度小w现在在点x上她想知道从点x出发经过每个点 ...
- 20180209-os模块
下面将学习关于os模块的相关操作 项目练习的目录结构如下:所有的操作都是基于os_exercise.py模块 1.获取当前的Python脚本的工作目录路径 os.getcwd() # 1.获取当前目录 ...
- maven system path,加载本地jar
当引用第三方包,且没有源代码时候,可以使用system path <dependency> <groupId>ctec</groupId> <artifact ...
- ed-tue-robotics
https://github.com/tue-robotics/ed ubuntu16.04 安装libsdformat4-dev ,libsdformat4 1./usr/include/sdfor ...
- RequestMappingHandlerMapping详解
我们先理简单梳理一个关系 关系梳理 spring ioc 是spring的核心,用来管理spring bean的生命周期 MVC 是一种使用 MVC(Model View Controller 模型- ...
- [BZOJ4278] [ONTAK2015]Tasowanie 贪心+后缀数组
题目链接 最近做题目好像有点东一榔头西一棒.好吧其实订正模拟题的时候需要用到什么感觉不太熟的就写一下吧. 显然直接贪心,比较两个点后面的串的字典序,小就选谁就可以了. 可以把两个串接起来,加一个\(i ...
- BZOJ4269 再见xor
考前挣扎 线性基裸题 mx直接求 次大直接从低到高枚举第一个非0位 然后次大就是异或上就行了[显然贪心呐qwq 不到800b可还行 //Love and Freedom. #include<cs ...
- B/S架构和C/S架构介绍
一.C/S架构 C/S架构及其背景 C/S架构是一种比较早的软件架构,主要应用于局域网内.在这之前经历了集中计算模式,随着计算机网络的进步与发展,尤其是可视化工具的应用,出现过两层C/S和三层C/S架 ...
- dubbo所用到的技术
服务注册:zookeeper 协议:dubbo Hessian Rmi 网络编程:netty 动态代理:jdk和Javassist 序列化:Hessian Dubbo Json Java S ...