oracle9i 怎样自动捕获DML 语句

oracle9i 怎样自动捕获DML 语句[@more@]SQL> desc t1
Name Null? Type
----------------------------------------------------- -------- ------------------------------------
A NUMBER

SQL> desc t_sql
Name Null? Type
----------------------------------------------------- -------- ------------------------------------
USERNAME VARCHAR2(30)
CLIENT_IP VARCHAR2(20)
SQL_TEXT VARCHAR2(4000)
TABLE_NAME VARCHAR2(30)
OWNER VARCHAR2(30)

SQL> create or replace trigger capt_sql
2 BEFORE DELETE OR INSERT OR UPDATE ON t1
3 declare
4 n number;
5 stmt varchar2(4000);
6 sql_text ora_name_list_t;
7 begin
8 n := ora_sql_txt(sql_text);
9 FOR i IN 1..n LOOP
10 stmt := stmt || sql_text(i);
11 END LOOP;
12
13 insert into t_sql(USERNAME,CLIENT_IP,SQL_TEXT,TABLE_NAME,OWNER)
14 values(user,sys_context('userenv','ip_address'),stmt,'T1','RAINY');
15
16 end;
17 /

Trigger created.

SQL> insert into t1(a) values(1);

1 row created.

SQL> update t1 set a = 2 where a = 1;

1 row updated.

SQL> delete t1;

3 rows deleted.

SQL> commit;

Commit complete.

SQL> select * from t_sql;

USERNAME CLIENT_IP SQL_TEXT
------------------------------ -------------------- ------------------------------
TABLE_NAME OWNER
------------------------------ ------------------------------
RAINY 10.1.30.19 insert into t1(a) values(1)
T1 RAINY

RAINY 10.1.30.19 update t1 set a = 2 where a =
1
T1 RAINY

RAINY 10.1.30.19 delete t1
T1 RAINY

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8643300/viewspace-890962/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/8643300/viewspace-890962/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值