更多精彩内容尽在 www.leonarding.com
Car表是一个非常重要的表,记录了4S店汽车的销量情况,我们要对操作这个表动作进行审计
LEO1@LEO1>select * from car;
NAME NUM COST
-------------------- ---------- ----------
toyota 10 30
volvo 50 30
honda 60 30
biaozhi 70 20
xuetielong 80 20
polo 90 20
xiali 20 10
jili 30 10
byd 40 10
9 rows selected.
创建审计表car_audit
LEO1@LEO1>create table car_audit (
name varchar2(20),
num number,
cost number,
uuser varchar2(20),
ddate date); 2 3 4 5 6
Table created.
创建审计触发器
LEO1@LEO1>create trigger trg_car_audit
after insert or delete or update on car
for each row
declare
a_name varchar2(20);
a_num number;
a_cost number;
begin
a_name :=:old.name;
a_num :=:old.num;
a_cost :=:old.cost;
insert into car_auditvalues(a_name,a_num,a_cost,user,sysdate);
end;
/
2 3 4 5 6 7 8 9 10 11 12 13 14
Trigger created.
删除记录
LEO1@LEO1>delete from car where num=100;
1 row deleted.
LEO1@LEO1>commit;
Commit complete.
插入记录
LEO1@LEO1>insert into carvalues('kia',100,50);
1 row created.
LEO1@LEO1>commit;
Commit complete.
更新记录
LEO1@LEO1>update car set num=200 wherenum=100;
1 row updated.
LEO1@LEO1>commit;
Commit complete.
凡是对car表进行DML操作都会触发审计触发器,并在car_audit表中留下审计记录
LEO1@LEO1>select * from car_audit;
NAME NUM COST UUSER DDATE
-------------------- ---------- ------------------------------ ---------
kia 100 50 LEO1 15-JUN-13
LEO1 15-JUN-13
kia 100 50 LEO1 15-JUN-13
Leonarding
2013.6.15
北京 &summer
分享技术~ 成就梦想
Blog:www.leonarding.com
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26686207/viewspace-764083/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26686207/viewspace-764083/