先建立一个表:
create table emp2_log values(uname varchar2(20),action varchar2(10),atime date);
如果往这个表中插入,删除,更改就会触发
create or replace trigger tri
after insert or delete or update on emp2 for each row
begin
if inserting then
insert into emp2_log values(user,'insert',sysdate);
elsif updating then
insert into emp2_log values(user,'update',sysdate);
elsif deleting then
insert into emp2_log values(user,'delete',sysdate);
end if;
end;
/
对于上面的for each row 语句在执行这条语句update emp2 set sal=sal*2 where deptno = 20;更新了5行,有for each row就在emp2_log里记录5条,没有for each row就只有一条记录。
如何成功执行update emp2 set deptno =88 where deptno2;
通常情况这样是不能执行成功的,因为有PK。但可以通过触发器完成这样的操作:
create or replace trigger trig
after update on dept for each row
begin
update emp2 set deptno = :NEW.deptno where deptno = :OLD.deptno;
end;
[@more@]来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21548840/viewspace-1035708/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/21548840/viewspace-1035708/