复合触发器范例

create or replace trigger compound_trigger

for insert or update or delete on dept_x

compound trigger

before statement is

begin

dbms_output.put_line('1:before statement.');

end before statement;

before each row is

begin

dbms_output.put_line('2:before each row.');

end before each row;

after each row is

begin

dbms_output.put_line('3:after each row');

end after each row;

after statement is

begin

dbms_output.put_line('4:after statement.');

end after statement;

end;

/

select * from dept_x;

DEPTNO DNAME   LOC

---------- -------------- -------------

10 ACCOUNTING   NEW YORK

20 RESEARCH   DALLAS

30 SALES   CHICAGO

40 OPERATIONS   BOSTON

delete dept_x;

1:before statement.

2:before each row.

3:after each row

2:before each row.

3:after each row

2:before each row.

3:after each row

2:before each row.

3:after each row

4:after statement.

4 rows deleted.

复合触发器范例

create or replace trigger compound_trigger

for insert or update or delete on dept

compound trigger

before each row is

begin

if inserting then

if :new.dname is null then

:new.dname:='VDEDU';

END IF;

if :new.loc is null then

:new.loc:='china';

end if;

end if;

end before each row;

end;

/

drop trigger compound_trigger;删除触发器

创建一个日志表,记录dept表的DML操作

create table dept_log(logid number,type varchar2(50),logdate date,deptno number,dname varchar2(50),loc varchar2(50));

create sequence dept_log_seq;

create or replace trigger dept_update_trigger10

before insert or update or delete

on dept

for each row

begin

if inserting then

insert into dept_log(logid,type,logdate,deptno,dname,loc)

values(dept_log_seq.nextval,'insert',sysdate,:new.deptno,:new.dname,:new.loc);

elsif updating then

insert into dept_log(logid,type,logdate,deptno,dname,loc)

values(dept_log_seq.nextval,'update',sysdate,:new.deptno,:new.dname,:new.loc);

else

insert into dept_log(logid,type,logdate,deptno,dname,loc)

values(dept_log_seq.nextval,'delete',sysdate,:old.deptno,:old.dname,:old.loc);

end if;

end;

/

PLSQL复合触发器的更多相关文章

  1. 【PLSQL】触发器trigger类型,状态,參数

    ************************************************************************   ****原文:blog.csdn.net/clar ...

  2. Oracle:复合触发器

    ----- CF_DEPTUCORGANIZATION  INSERT UPDATE DELETE 触发器CREATE  OR REPLACE TRIGGER tr_del_CF_DEPTUCORGA ...

  3. plsql programming 19 触发器

    挂起语句, 是指数据库 Hang 到那不能动了, 触发的. 1. DML 触发器 这种类型的触发器对于开发人员都很常见, 其他类型的触发器主要是给DBA使用的. 配置触发器,我们需要回答以下问题: 触 ...

  4. pl/sql学习(5): 触发器trigger/事务和锁

    (一)触发器简单介绍 触发器是由数据库的特定时间来触发的, 特定事件主要包括以下几种类型: (1)DML: insert, update,delete 增删改 (2)DDL: create, alte ...

  5. plsql实例精讲部分笔记

    转换sql: create or replace view v_sale(year,month1,month2,month3,month4,month5,month6,month7,month8,mo ...

  6. PLSQL开发笔记和小结(转载)

    *****************************************   PLSQL基本结构 ***************************************** 基本数据 ...

  7. Oracle之PLSQL总结

    基本数据类型变量 1. 基本数据类型     Number 数字型     Int 整数型     Pls_integer 整数型,产生溢出时出现错误 Binary_integer 整数型,表示带符号 ...

  8. PLSQL开发笔记和小结

    *****************************************  PLSQL基本结构*****************************************基本数据类型变 ...

  9. PL/SQL 编程(三 )程序包和包体,触发器,视图,索引

    一.程序包和包体 程序包(package):存储在数据库中的一组子程序.变量定义.在包中的子程序可以被其它程序包或子程序调用.但如果声明的是局部子程序,则只能在定义该局部子程序的块中调用该局部子程序. ...

随机推荐

  1. iOS开发:一个无限滚动自动播放图片的Demo(Swift语言编码)

    很久以前就想写这么一个无限滚动的Demo了,最近学习了下Swift,手中没有可以用来练手的Demo,所以才将它实现了. Github地址(由于使用了UIView+AutoLayout第三方进行布局,所 ...

  2. rc.d/rc.local 自动启 tomcat 启不来

    针对自己配置的JDK环境有可能会出现这样的情况. tomcat能启来.但自启动就不行,原因 JDK是后安装的,环境变量配置在 /etc/profile 里面. tomcat 配了自启动.但reboot ...

  3. Spring Security 指定登陆入口

    spring security除通过form-login的熟悉指定登陆还可以通过entry-point-ref 指定登陆入口.具体配置如下: <?xml version="1.0&qu ...

  4. Unity5 AssetBundle系列——资源加载卸载以及AssetBundleManifest的使用

    下面代码列出了对于assetbundle资源的常用操作,其中有针对bundle.asset.gameobject三种类型对象的操作,实际使用中尽量保证成对使用. 这一块的操作比较繁琐,但只要使用正确, ...

  5. Java知多少(23)类的基本运行顺序

    我们以下面的类来说明一个基本的 Java 类的运行顺序: public class Demo{ private String name; private int age; public Demo(){ ...

  6. 【转帖】Mysql多维数据仓库指南 第一篇 第1章

     Mysql多维数据仓库指南 第一篇基本原理 章节列表: 第1章:基本组成 第2章:维度历史 第3章:维度可加性 第4章:维度查询 本篇概述 你将运用关系数据库来实施一个维度数据仓库.事实表和维表这两 ...

  7. (笔记)Linux内核学习(一)之内核介绍

    内核与操作系统: 内核是操作系统的核心部分,包含了系统运行的核心过程,决定系统的性能,操作系统启动内核被装入到RAM中: 操作系统与底层硬件设备交互和为运行应用程序提供执行环境. Linux内核与微内 ...

  8. Hadoop、Spark 集群环境搭建

    1.基础环境搭建 1.1运行环境说明 1.1.1硬软件环境 主机操作系统:Windows 64位,四核8线程,主频3.2G,8G内存 虚拟软件:VMware Workstation Pro 虚拟机操作 ...

  9. CXF总结

    CXF总结 如何来用cxf结合spring开发webservice接口.by@wangkun 下载cxf 下载地址:http://cxf.apache.org/download.html 我下载的版本 ...

  10. python -u 启动python文件的作用,PYTHONUNBUFFERED环境变量的作用

    python -u 启动python文件的作用是不缓存,直接把输出重定向到文件,比如nohup启动什么的,如果不使用-u启动,那么程序中的print和日志什么的,可能不会非常及时的重定向到out文件, ...