觸發語句 |
: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;