Я могу создать этот триггер от пользователя, не являющегося системным пользователем.
-- Execute from sys user
CREATE USER T IDENTIFIED BY <Password>
default tablespace <Default_tablespace>;
ALTER USER T QUOTA UNLIMITED ON <Default_tablespace>;
GRANT CONNECT, RESOURCE TO T;
GRANT ADMINISTER DATABASE TRIGGER TO T;
-
-- Execute from T user
CREATE TABLE AUDIT_LOG (
LOG_ID NUMBER
GENERATED ALWAYS AS IDENTITY,
USER_NAME VARCHAR2(4000),
DLL_TYPE VARCHAR2(4000),
OBJECT_NAME VARCHAR2(4000),
OBJECT_TYPE VARCHAR2(4000),
OBJECT_SCRIPT CLOB
);
CREATE OR REPLACE TRIGGER TRG_CATCH_AFTER_DDL AFTER DDL ON DATABASE DECLARE
SQL_TEXT ORA_NAME_LIST_T;
N PLS_INTEGER;
V_SQL CLOB;
V_ID NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE(ORA_SYSEVENT);
IF ORA_SYSEVENT IN (
'DROP',
'ALTER',
'ANALYZE'
) THEN
/*alter table must be handle*/
NULL; -- this is not finished
ELSE
IF ORA_DICT_OBJ_TYPE = 'TABLE' THEN
V_SQL := DBMS_METADATA.GET_DDL(ORA_DICT_OBJ_TYPE, ORA_DICT_OBJ_NAME, ORA_LOGIN_USER);
ELSE
N := ORA_SQL_TXT(SQL_TEXT);
FOR I IN 1..N LOOP
V_SQL := V_SQL || SQL_TEXT(I);
END LOOP;
END IF;
INSERT INTO audit_log
(user_name, dll_type, object_name, object_type, object_script)
VALUES
(ora_login_user,
ora_sysevent,
ora_dict_obj_name,
ora_dict_obj_type,
v_sql)
RETURNING log_id INTO v_id;
--
-- pcd_source_writer(id => v_id);
END IF;
END TRG_CATCH_AFTER_DDL;
/
-
-- Testing:
DROP SEQUENCE TEMP_SEQ;
CREATE SEQUENCE TEMP_SEQ START WITH 1 INCREMENT BY 1 MAXVALUE 100;
ALTER SEQUENCE TEMP_SEQ INCREMENT BY 2;
-
-- Result:
SELECT * FROM audit_log;
Выход:
Надеюсь, вам это пригодится.
Ура !!