How can we create a drop partition DDL trigger in Oracle. For eg Suppose we create DDL trigger to capture or prevent if someone fires drop TABLE/INDEX or naything in our schema. Create or replace trigger my_trg After DROP on schema
Can we do same for drop partition .
Can we store the detail ..like this partition was dropped by this particular user.
Can we prevent user from dropping partition through trigger or capture which user dropped the partition
The trigger would be this one:
CREATE OR REPLACE TRIGGER LOG_ALTER
BEFORE ALTER ON SCHEMA
WHEN (ora_dict_obj_type = 'TABLE' AND ora_dict_obj_name = 'YOUR_TABLE')
DECLARE
sqlcmd T_USER_LOGGING.ULOG_SQL_CMD%TYPE;
sql_text ora_name_list_t;
n NUMBER;
BEGIN
n := ora_sql_txt(sql_text);
IF n IS NOT NULL THEN
FOR i IN 1..n LOOP
sqlcmd := sqlcmd || sql_text(i);
END LOOP;
END IF;
IF REGEXP_LIKE(sqlcmd, 'DROP\s+PARTITION', 'i') THEN
RAISE_APPLICATION_ERROR(-20010, 'User '||ora_login_user||' must not drop partition from table YOUR_TABLE');
END IF;
END;
/
But note, a user with ADMINISTER DATABASE TRIGGER
system privilege can drop the partition anyway as he ignores the RAISE_APPLICATION_ERROR
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.