Header Ads

Header ADS

Trigger Drop by Oracle Procedure

Trigger Drop by Oracle Procedure

Topic Introduction: "Trigger Drop by Oracle Procedure", By the drop command, we can delete any trigger from our database. In this post, we will show how to delete or drop a trigger by PL/SQL Procedure.

1. Procedure Creation for Trigger Drop

CREATE OR REPLACE PROCEDURE drop_trigger_if_exists(
    p_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(p_trigger_name);
    
    -- if the trigger exist, drop it
    IF l_exist > 0 THEN 
        EXECUTE IMMEDIATE 'DROP TRIGGER ' ||  p_trigger_name;
    END IF;
END;

2. Procedure Execution for Trigger Drop

EXEC drop_trigger_if_exists('customers_credit_trg'); 

No comments

Theme images by Deejpilot. Powered by Blogger.