真实使用场景:数据备份

1. 触发器的 helloworld: 编写一个触发器, 在向 emp 表中插入记录时, 打印 'helloworld'

create or replace trigger emp_trigger

after insert on emp

for each row

begin

dbms_output.put_line('helloworld');

end;

2. 行级触发器: 每更新 employees 表中的一条记录, 都会导致触发器执行

create or replace trigger employees_trigger

after update on employees

for each row--行级触发器

begin

dbms_output.put_line('修改了一条记录!');

end;

3.语句级触发器: 一个 update 语句只使触发器执行一次

create or replace trigger employees_trigger

after update on employees

begin

dbms_output.put_line('修改了一条记录!');

end;

4. 使用 :new, :old 修饰符

create or replace trigger employees_trigger

after update on employees

for each row

begin

dbms_output.put_line('old salary: ' || :old.salary || ', new salary: ' || :new.salary);

end;

5. 编写一个触发器, 在对 my_emp 记录进行删除的时候, 在 my_emp_bak 表中备份对应的记录

1). 准备工作:

create table my_emp as select employee_id id, last_name name, salary sal from employees

create table my_emp_bak as select employee_id id, last_name name, salary sal from employees where 1 = 2

2).

create or replace trigger bak_emp_trigger

before delete

on my_emp

for each row

begin

insert into my_emp_bak values(:old.id, :old.name, :old.sal);

end;

oracle 10g 学习之触发器(13)的更多相关文章

  1. oracle 10g 学习之服务器端安装(1)

    Oracle 简介 lOracle 是殷墟出土的甲骨文(oracle bone inscriptions)的英文翻译的第一个单词 lOracle 公司是全球最大的信息管理软件及服务供应商,成立于197 ...

  2. oracle 10g 学习之视图、序列、索引、同义词(9)

    目标 通过本章学习,您将可以: l  描述视图 l  创建和修改视图的定义,删除视图 l  从视图中查询数据 l  通过视图插入, 修改和删除数据 l  使用“Top-N” 分析 l  创建, 维护, ...

  3. oracle 10g 学习之数据进行增删改查、数据库事务、约束(8)

    目标 通过本章学习,您将可以: l  使用 DML 语句 l  向表中插入数据 l  更新表中数据 l  从表中删除数据 l  控制事务 l  描述约束 l  创建和维护约束 数据控制语言 l     ...

  4. oracle 10g 学习之创建和管理表(7)

    目标 通过本章学习,您将可以: l  描述主要的数据库对象. l  创建表. l  描述各种数据类型. l  修改表的定义. l  删除,重命名和清空表. 常见的数据库对象 表.视图.序列.索引.同义 ...

  5. oracle 10g 学习之单行函数(5)

    目标 通过本章学习,您将可以: l  SQL中不同类型的函数. l  在 SELECT 语句中使用字符,数字和日期函数. l  描述转换型函数的用途. 字符函数 字符函数分为大小写控制函数和字符控制函 ...

  6. oracle 10g 学习之oracle管理(3)

    怎样将预先写好的sql脚本执行? select * from employees;→107条记录 利用 Oracle 企业管理器连接数据库服务器 点击打开以下界面: 此时已经连接成功了 用 Oracl ...

  7. oracle 10g 学习之.NET使用Oracle数据库(14)

    因为使用System.Data.OracleClient会提示过时,推荐使用oracle自己提供的.net类库Oracle.DataAccess.Client 在oracle C:\oracle\pr ...

  8. oracle 10g 学习之函数和存储过程(12)

    一.函数 1. 函数的 helloworld: 返回一个 "helloworld--!" 的字符串 create or replace function helloworld re ...

  9. oracle 10g 学习之游标使用和异常介绍(11)

    一.游标 1. 使用游标 要求: 打印出 80 部门的所有的员工的工资: salary: xxx declare --1. 定义游标 cursor salary_cursor is select sa ...

随机推荐

  1. SQL防注入程序

    1.在Global.asax.cs中写入: protected void Application_BeginRequest(Object sender,EventArgs e){      SqlIn ...

  2. php 命名空间

    命名空间一个最明确的目的就是解决重名问题,PHP中不允许两个函数或者类出现相同的名字,否则会产生一个致命的错误.这种情况下只要避免命名重复就可以解决,最常见的一种做法是约定一个前缀. 例:项目中有两个 ...

  3. iOS-UIView category

    UIView+Extension.h #import <UIKit/UIKit.h> @interface UIView (Extension) @property (nonatomic, ...

  4. CentOS创建免密码SSH(密钥)

    1.输入以下命令:ssh-keygen -t rsa 2.输入命令ls:产生两个文件:id_rsa id_rsa.pub 3.复制id_rsa.pub,并命名为authorized_key cp ~/ ...

  5. <转>错误 x error LNK1104: 无法打开文件“E:\xxxx\Debug\xxxx.exe”

    刚刚还好好的,怎么突然就出现这样的错误, 后来分析原因, 第一:查看那个exe文件是否存在, 第二:查看那个文件或者那个文件所在的文件夹是否打开或者改名字等等操作占用着这个文件. 第三:重新清理并生成 ...

  6. Todd's Matlab讲义第1讲:向量,函数和作图

    向量 Matlab 中最基本的对象是矩阵,向量是特殊的矩阵.行向量是\(1\times n\)矩阵,列向量是\(m\times 1\)矩阵.输入如下行向量: >> v=[0 1 2 3] ...

  7. Milking Cows

    Milking Cows Three farmers rise at 5 am each morning and head for the barn to milk three cows. The f ...

  8. stringbuffer 和 stringbuilder的区别

    1. stringbuffer 和 stringbuilder的区别 StringBuffer是线程安全的, 这个类里的所有方法是同步的.这个反过来就会对程序的性能有一定的影响.StringBuild ...

  9. FOJ 2161 Jason and Number

    暴力模拟找规律: 552287 2014-04-23 21:08:48 Accepted 2161 Visual C++ 0 ms 192KB 347B Watermelon #include< ...

  10. HDOJ 2066 floyed优化算法

    一个人的旅行 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...