oracle触发器demo分享
程序员文章站
2022-07-05 23:31:47
--触发器
--语句级触发器(只执行一次)
--触发发生在添加之前
create or replace trigger tg1
after insert
on emp...
--触发器
--语句级触发器(只执行一次)
--触发发生在添加之前
create or replace trigger tg1 after insert on emp01 declare n int; begin select count(*) into n from emp01; dbms_output.put_line('emp01表*有'||n||'条记录!'); end; insert into emp01 values(1,'小米','学生',2025,'3-10月-2015',1000,200,10); --行级触发器 --delete 将删除的数据放在old表中 --insert 将新的数据放在new表中 --update 将原始的数据放在old表中,再在new表中存放新值 create table emp02 as select * from emp01 where 1<>1; select * from emp02; select * from emp01; create or replace trigger tg2 after delete on emp01 for each row declare begin insert into emp02 values(:old.empno,:old.ename,:old.job,:old.mgr,:old.hiredate,:old.sal,:old.comm,:old.deptno); end; delete from emp01 where empno=7369; select * from emp02; select * from emp01;