oracle 10g 学习之触发器(13)
真实使用场景:数据备份
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)的更多相关文章
- oracle 10g 学习之服务器端安装(1)
Oracle 简介 lOracle 是殷墟出土的甲骨文(oracle bone inscriptions)的英文翻译的第一个单词 lOracle 公司是全球最大的信息管理软件及服务供应商,成立于197 ...
- oracle 10g 学习之视图、序列、索引、同义词(9)
目标 通过本章学习,您将可以: l 描述视图 l 创建和修改视图的定义,删除视图 l 从视图中查询数据 l 通过视图插入, 修改和删除数据 l 使用“Top-N” 分析 l 创建, 维护, ...
- oracle 10g 学习之数据进行增删改查、数据库事务、约束(8)
目标 通过本章学习,您将可以: l 使用 DML 语句 l 向表中插入数据 l 更新表中数据 l 从表中删除数据 l 控制事务 l 描述约束 l 创建和维护约束 数据控制语言 l ...
- oracle 10g 学习之创建和管理表(7)
目标 通过本章学习,您将可以: l 描述主要的数据库对象. l 创建表. l 描述各种数据类型. l 修改表的定义. l 删除,重命名和清空表. 常见的数据库对象 表.视图.序列.索引.同义 ...
- oracle 10g 学习之单行函数(5)
目标 通过本章学习,您将可以: l SQL中不同类型的函数. l 在 SELECT 语句中使用字符,数字和日期函数. l 描述转换型函数的用途. 字符函数 字符函数分为大小写控制函数和字符控制函 ...
- oracle 10g 学习之oracle管理(3)
怎样将预先写好的sql脚本执行? select * from employees;→107条记录 利用 Oracle 企业管理器连接数据库服务器 点击打开以下界面: 此时已经连接成功了 用 Oracl ...
- oracle 10g 学习之.NET使用Oracle数据库(14)
因为使用System.Data.OracleClient会提示过时,推荐使用oracle自己提供的.net类库Oracle.DataAccess.Client 在oracle C:\oracle\pr ...
- oracle 10g 学习之函数和存储过程(12)
一.函数 1. 函数的 helloworld: 返回一个 "helloworld--!" 的字符串 create or replace function helloworld re ...
- oracle 10g 学习之游标使用和异常介绍(11)
一.游标 1. 使用游标 要求: 打印出 80 部门的所有的员工的工资: salary: xxx declare --1. 定义游标 cursor salary_cursor is select sa ...
随机推荐
- iptable
http://blog.sina.com.cn/s/blog_6fbf7e670101d60i.html
- FCK编辑器漏洞总结
1.查看编辑器版本FCKeditor/_whatsnew.html————————————————————————————————————————————————————————————— 2. Ve ...
- 百度或者Google---SEO优化(转载)
google 和百度的技术差别: 1.百度还认不清哪个是原创的 2.google蜘蛛不够百度快 4.google排名结果随时变化 流量.权重.权威.内容.用户体验.用户关注度等等细节的排名,已表 达了 ...
- iOS ASIHTTPRequest用https协议加密请求
iOS 终端请求服务端数据时,为了保证数据安全,我们一般会使用https协议加密,而对于iOS的网络编程,我们一般会使用开源框架:ASIHTTPRequest,但是如果使用传统的http方式,即使忽略 ...
- Objective-C 之优雅的命名(转)
There are only two hard things in Computer Science: cache invalidation and naming things. 在计算机科学中只有两 ...
- 为自己的git添加alias,命令缩写
在多人协作开发时,一般用git来进行代码管理.git有一些命令如:git pull . git push等等,这些命令可以设置alias,也就是缩写.如:git pull 是 git pl, git ...
- HDOJ 2389 Rain on your Parade
HK.... Rain on your Parade Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 655350/165535 K ...
- 微信用户量破6.5亿 首超移动QQ
腾讯控股有限公司昨日公布了微信和WeChat合并月活跃用户量达到6.5亿,同比再涨39%.QQ在移动智能终端月活为6.39亿,同比增长18%,尽管势头也不错,但这是第一次,微信干掉了移动QQ! 201 ...
- php页面打开响应时间
$start_time = array_sum(explode(' ',microtime())); //your code here $end_time = array_sum(explode( ...
- CC MayClg 15 T3
www.codechef.com/MAY15/problems/CHAPD 一道比较神奇的题目... 看到题目后自己yy出了个傻逼算法...然后对拍都是对的...提交都是错的...然后一看" ...