create or replace trigger trigg_trace
after insert or update or delete on t1
for each row
declare
-- local variables here
v_id int;
v_name varchar2(10);
v_flag varchar2(10);
begin
if inserting then
v_id := :new.id;
v_name :=:new.name;
v_flag :='insert';
else
if updating then
v_flag :='update' ;
else
v_flag :='delete' ;
end if ;
v_id := :old.id;
v_name :=:old.name;
end if ;
insert into t_trace
values(sys.login_user,
sys_context('userenv','ip_address'),
sys_context('userenv','terminal'),
sysdate,
v_id,
v_name,
v_flag);
end trigg_trace;
--==========================
SQL> desc t1
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
ID NUMBER(38)
NAME VARCHAR2(10)
SQL> desc t_trace
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
USERNAME VARCHAR2(10)
IP_ADDRESS VARCHAR2(30)
TERMINAL VARCHAR2(10)
TIME DATE
ID NUMBER(38)
NAME VARCHAR2(10)
ACTION VARCHAR2(20)
SQL>
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/19602/viewspace-1019014/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/19602/viewspace-1019014/