DB version: 19c
I am a relative beginner in PL/SQL .
I have a trigger named DDL_PREVENTOR_TRG owned by SYS.
Case1)
On some Pluggable DBs, this trigger exists and it is ENABLED (as shown below)
SQL> alter session set container = PDB_SALES;
Session altered.
SQL> col owner for a18
SQL> select owner, status from dba_Triggers where trigger_name = 'DDL_PREVENTOR_TRG';
OWNER STATUS
------------------ --------
SYS ENABLED
Case2) On some PDBs, it exists but in DISABLED state.
SQL> select owner, status from dba_Triggers where trigger_name = 'DDL_PREVENTOR_TRG';
OWNER STATUS
------------------ --------
SYS DISABLED
Case3) On some PDBs, it does not exist at all.
SQL> select owner, status from dba_Triggers where trigger_name = 'DDL_PREVENTOR_TRG';
no rows selected
I want to write a short PL/SQL anonymous block, which will handle the below 3 cases.
-
Disable this trigger if it exists and the trigger is ENABLED (Case1 above)
-
Do nothing when the trigger exists and already disabled (Case2 above)
-
Do nothing when the trigger does not even exist in the PDB (Case3 above)
Any idea how I can do it ? I wrote the below skeleton.
DECLARE
v_status varchar2(50);
BEGIN
select status into v_status from dba_Triggers where trigger_name = 'DDL_PREVENTOR_TRG';
if
v_status = ....
then
execute immediate 'alter trigger sys.DDL_PREVENTOR_TRG disable' ;
end if;
END;
/