Posted on 2010-07-24 16:22
断点 阅读(291)
评论(0) 编辑 收藏 所属分类:
Oracle DBA
--触发器
create table emp2_log
(
uname varchar2(20);
action varchar2(10);
atime date
);
create or replace trigger trig
after insert or delete or update on emp2 for each row
begin
if inserting then
insert into emp2_log values (USER,'insert',sysdate); --USER关键字,用户。
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;
update emp2 set sal = sal*2 where deptno = 30;
select * from emp2_log;
drop trigger trig;
--直接执行时,出现违反完整约束条件,已找到子记录。
update dept set deptno = 99 where deptno = 10;
--使用下面的,把子表一起更新。
create or replace trigger trig
after update on dept for each row
begin
update emp set deptno =:NEW.deptno where deptno =:OLD.deptno;
end;
update dept set deptno = 99 where deptno = 10;
select * from emp;
rollback;