触发语句 | :old | :new |
Insert | 所有字段都是空(null) | 将要插入的数据 |
Update | 更新以前该行的值 | 更新后的值 |
delete | 删除以前该行的值 | 所有字段都是空(null) |
示例2:确认数据(检查emp表中sal的修改值不低于原值)
SQL> create or replace trigger checkSal
before update of sal on emp
for each row
declare
begin
if :new.sal<:old.sal then
raise_application_error(-20001,'更新后的薪水比更新前小');
end if;
end;
/
Trigger created
运行后结果:
SQL> update emp set sal=260 where empno=7499;
update emp set sal=260 where empno=7499
ORA-20001: 更新后的薪水比更新前小
ORA-06512: 在 "SCOTT.CHECKSAL", line 4
ORA-04088: 触发器 'SCOTT.CHECKSAL'执行过程中出错
触发器总结
触发器可用于
• 数据确认
• 实施复杂的安全性检查
• 做审计,跟踪表上所做的数据操作等
查询触发器、过程及函数
• Select * from user_triggers;
• Select * from user_source;
新闻热点
疑难解答