--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;