CREATE OR REPLACE TRIGGER tr_trace_ddl
AFTER DDL ON DATABASE
DECLARE
sql_text ora_name_list_t;
state_sql ddl$trace.ddl_sql%TYPE;
BEGIN
FOR i IN 1..ora_sql_txt(sql_text) LOOP
state_sql := state_sql||sql_text(i);
END LOOP;
INSERT INTO ddl$trace(login_user,ddl_time,ip_address,audsid,
schema_user,schema_object,ddl_sql)
VALUES(ora_login_user,SYSDATE,userenv('SESSIONID'),
sys_context('USERENV','IP_ADDRESS'),
ora_dict_obj_owner,ora_dict_obj_name,state_sql);
EXCEPTION
WHEN OTHERS THEN
null;
END tr_trace_ddl;
在创建以上触发器时要注意几点
必须创建一个ddl$trace的表,用来记录ddl的记录
CREATE TABLE SYS.DDL$TRACE
(
LOGIN_USER VARCHAR2(50 BYTE),
DDL_TIME DATE,
IP_ADDRESS VARCHAR2(50 BYTE),
AUDSID VARCHAR2(50 BYTE),
SCHEMA_USER VARCHAR2(20 BYTE),
SCHEMA_OBJECT VARCHAR2(50 BYTE),
DDL_SQL VARCHAR2(4000 BYTE)
);
阅读(1221) | 评论(0) | 转发(0) |