Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

PL/SQL code to disable a trigger

Mark82Apr 25 2025

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.

  1. Disable this trigger if it exists and the trigger is ENABLED (Case1 above)

  2. Do nothing when the trigger exists and already disabled (Case2 above)

  3. 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;
/
This post has been answered by Frank Kulash on Apr 25 2025
Jump to Answer
Comments
Post Details
Added on Apr 25 2025
3 comments
166 views