触发器after和before
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了触发器after和before相关的知识,希望对你有一定的参考价值。
--after和before CREATE OR REPLACE TRIGGER del_emp1 BEFORE update OR insert OR delete ON scott.emp REFERENCING new AS nn old AS oo FOR EACH ROW WHEN (nn.sal > 2000) BEGIN IF INSERTING THEN dbms_output.put_line(‘THE OPERATION IS INSERT‘); ELSIF UPDATING THEN dbms_output.put_line(‘THE OPERATION IS UPDATE‘); ELSIF DELETING THEN dbms_output.put_line(‘THE OPERATION IS DELETE‘); ELSE dbms_output.put_line(‘OTHERS OPERATION‘); END IF; END; CREATE OR REPLACE TRIGGER del_emp2 after update OR insert OR delete ON scott.emp REFERENCING new AS nn old AS oo FOR EACH ROW WHEN (nn.sal > 2000) BEGIN IF INSERTING THEN dbms_output.put_line(‘THE OPERATION IS INSERT‘); ELSIF UPDATING THEN dbms_output.put_line(‘THE OPERATION IS UPDATE‘); ELSIF DELETING THEN dbms_output.put_line(‘THE OPERATION IS DELETE‘); ELSE dbms_output.put_line(‘OTHERS OPERATION‘); END IF; END; update emp set sal=7000 where emp.ename=‘SMITH‘; --after和before的区别是:before是先执行begin后触发触发器,after是先执行触发器而后执行begin内容. CREATE OR REPLACE TRIGGER check_emp BEFORE update OR insert OR delete ON scott.emp REFERENCING new AS nn old AS oo FOR EACH ROW /*WHEN (nn.sal < 2000)*/ BEGIN IF INSERTING THEN dbms_output.put_line(‘THE OPERATION IS INSERT‘); ELSIF UPDATING THEN dbms_output.put_line(‘THE OPERATION IS UPDATE‘); ELSIF DELETING THEN dbms_output.put_line(‘THE OPERATION IS DELETE‘); ELSE dbms_output.put_line(‘OTHERS OPERATION‘); END IF; END; select * from emp; begin savepoint s1; delete emp where sal=4000; rollback to s1; end;
以上是关于触发器after和before的主要内容,如果未能解决你的问题,请参考以下文章