I want to make an history on an Oracle DB about all the DDL operations which are executed by the time.
I have created a TABLE
and a DDL TRIGGER
for do that, in this way:
CREATE TABLE AUDIT_DDL (
D DATE,
OSUSER VARCHAR2(255),
CURRENT_USER VARCHAR2(255),
HOST VARCHAR2(255),
TERMINAL VARCHAR2(255),
OWNER VARCHAR2(30),
TYPE VARCHAR2(30),
NAME VARCHAR2(30),
SYSEVENT VARCHAR2(30));
--/
CREATE OR REPLACE TRIGGER AUDIT_DDL_TRG AFTER DDL ON SCHEMA
BEGIN
IF (ORA_SYSEVENT='TRUNCATE')
THEN
NULL;
ELSE
INSERT INTO AUDIT_DDL(D, OSUSER,CURRENT_USER,HOST,TERMINAL,OWNER,TYPE,NAME,SYSEVENT)
VALUES(
SYSDATE,
SYS_CONTEXT('USERENV','OS_USER') ,
SYS_CONTEXT('USERENV','CURRENT_USER') ,
SYS_CONTEXT('USERENV','HOST') ,
SYS_CONTEXT('USERENV','TERMINAL') ,
ORA_DICT_OBJ_OWNER,
ORA_DICT_OBJ_TYPE,
ORA_DICT_OBJ_NAME,
ORA_SYSEVENT
);
END IF;
END;
/
This works perfectly: after each DDL statement, I have a new row in the AUDIT_DDL table.
But I still don't have any information about the exact kind of operation has been made.
For example, the following two statements will produce the same ALTER
SYSEVENT in the AUDIT_DDL table:
ALTER TABLE MYTABLE RENAME COLUMN TEMP TO NEWTEMP;
ALTER TABLE MYTABLE DROP COLUMN NEWTEMP;
So, in this way, I can't know what operation has been made rather than a generic ALTER TABLE
, and I can't even know if the column TEMP has been renamed or dropped from the table MYTABLE!
My question is: how can I retrieve some more information about the event has occurred after the DDL execution (object involved, details, etc...)?