You are on page 1of 3

10/17/22, 4:33 PM Learn Oracle DROP TRIGGER By Practical Examples

Oracle DROP TRIGGER

Summary: in this tutorial, you will learn how to use the Oracle DROP TRIGGER statement to remove
a trigger from the database.

Introduction to the Oracle DROP TRIGGER statement


The DROP TRIGGER statement allows you to remove a trigger (https://www.oracletutorial.com/plsql-
tutorial/oracle-trigger/) from the database.

Here is the basic syntax of the DROP TRIGGER statement:

DROP TRIGGER [schema_name.]trigger_name;

In this syntax, you specify the name of the trigger that you want to remove after the DROP TRIGGER
keywords.

Optionally, you can specify the name of the schema to which the trigger belongs. If you skip the
schema_name , Oracle will assume that the trigger is in your own schema.

Note that the trigger that you remove must be in your own schema or you must have the
DROP ANY TRIGGER system privilege (https://www.oracletutorial.com/oracle-administration/oracle-grant/)
.

If you attempt to remove a trigger that does not exist, Oracle will issue the error ORA-04080 ,
indicating that the trigger does not exist.

Unlike other database systems like SQL Server (http://www.sqlservertutorial.net/sql-server-triggers/sql-server-


drop-trigger/) and PostgreSQL (http://www.postgresqltutorial.com/postgresql-drop-trigger/) , Oracle does not
support IF EXISTS option to drop a trigger only if it exists. Therefore, the following syntax is not
valid in Oracle:

DROP TRIGGER IF EXISTS trigger_name;

https://www.oracletutorial.com/plsql-tutorial/oracle-drop-trigger/ 1/3
10/17/22, 4:33 PM Learn Oracle DROP TRIGGER By Practical Examples

Fortunately, you can develop a procedure (https://www.oracletutorial.com/plsql-tutorial/plsql-procedure/) that


combines the DROP TRIGGER statement with dynamic SQL to drop a trigger only if it exists as
follows:

CREATE OR REPLACE PROCEDURE drop_trigger_if_exists(

in_trigger_name VARCHAR2

AS

l_exist PLS_INTEGER;

BEGIN

-- get the trigger count

SELECT COUNT(*) INTO l_exist

FROM user_triggers

WHERE trigger_name = UPPER(in_trigger_name);

-- if the trigger exist, drop it

IF l_exist > 0 THEN

EXECUTE IMMEDIATE 'DROP TRIGGER ' || in_trigger_name;

END IF;

END;

In this procedure:

First, get the number of triggers that matches the input trigger from the user_triggers data
dictionary view using the COUNT() (https://www.oracletutorial.com/oracle-aggregate-functions/oracle-

count/) function.

Then, use the EXECUTE IMMEDIATE statement to execute a dynamic SQL statement which
removes the trigger.

Oracle DROP TRIGGER statement examples


The following statement drops the trigger customers_audit_trg of the customers table:

DROP TRIGGER customers_audit_trg;

https://www.oracletutorial.com/plsql-tutorial/oracle-drop-trigger/ 2/3
10/17/22, 4:33 PM Learn Oracle DROP TRIGGER By Practical Examples

This example uses the procedure drop_trigger_if_exists to drop the trigger


customers_credit_trg :

EXEC drop_trigger_if_exists('customers_credit_trg');

And this example use the drop_trigger_if_exists procedure to remove a trigger that does not
exist:

EXEC drop_trigger_if_exists('customers_xyz_trg');

In this tutorial, you have learned how to use the Oracle DROP TRIGGER statement to remove a
trigger from the database.

https://www.oracletutorial.com/plsql-tutorial/oracle-drop-trigger/ 3/3

You might also like