记录日志
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
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;
/
操作emp2表
update emp2 set sal = sal*2 where deptno=30;
查看emp2_log表
select uname,action,to_char(atime,'YYYY-MM-DD HH24:MI:SS') from emp2_log;
只显示一行数据
(二)
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);
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;
显示7行数据
注:for each row ,每一行触发一次