删除oracle 审计数据,Oracle中审计删除(DELETE)操作的触发器

帮朋友写的一个简单审计删除操作的触发器,供参考。

首先是授权:

SQL> connect / as sysdba

Connected.

SQL> grant select on v_$sql to eygle;

Grant succeeded.

SQL> grant select on v_$session to eygle;

Grant succeeded.创建测试表及审计表:

SQL> connect eygle/eygle

Connected.

SQL> create table eygle as select user_id,username from dba_users;

Table created.

SQL> desc eygle

Name                                      Null?    Type

----------------------------------------- -------- ----------------------------

USER_ID                                   NOT NULL NUMBER

USERNAME                                  NOT NULL VARCHAR2(30)

SQL> create table eygle_delete_audit

2  (user_id number,username varchar2(30),deleteby varchar2(30),deldate date,ipaddress varchar2(50),sqltext clob);

Table created.创建如下触发器:

CREATE OR REPLACE TRIGGER eygle_after_delete

AFTER DELETE

ON eygle

FOR EACH ROW

BEGIN

INSERT INTO eygle_delete_audit

SELECT :old.user_id,:old.username,user,sysdate,SYS_CONTEXT ('userenv', 'ip_address')

,q.sql_text

FROM v$sql q, v$session s

WHERE s.audsid = (SELECT USERENV ('SESSIONID') FROM DUAL)

AND s.sql_id = q.sql_id;

END;

/测试删除操作:

SQL> connect eygle/eygle@rac1

Connected.

SQL> delete from eygle where user_id=46;

1 row deleted.

SQL> commit;

Commit complete.

SQL> truncate table eygle_delete_audit;

Table truncated.

SQL> delete from eygle where user_id=0;

1 row deleted.

SQL> commit;

Commit complete.

SQL> select * from eygle_delete_audit;

USER_ID USERNAME                       DELETEBY

---------- ------------------------------ ------------------------------

DELDATE      IPADDRESS

------------ --------------------------------------------------

SQLTEXT

--------------------------------------------------------------------------------

0 SYS                            EYGLE

12-JAN-11    172.16.3.248

delete from eygle where user_id=0

能够成功记录删除信息及SQL,不知是否有其他问题,请建议!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值