Oracle PL/SQL – Rename Trigger
By:Roy.LiuLast updated:2019-08-11
This article shows you how to use ALTER TRIGGER to rename a trigger.
-- rename a trigger ALTER TRIGGER original_name RENAME TO new_name;
1. Table + Trigger
electricity_bill
create table electricity_bill bill_id number(5) primary key, amount number(5) ); -- Table ELECTRICITY_BILL created.
trg_rename_example
CREATE OR REPLACE TRIGGER trg_rename_example BEFORE UPDATE OR DELETE OR INSERT ON electricity_bill FOR EACH ROW BEGIN dbms_output.put_line('trg_rename_example Trigger called.'); END; -- Trigger TRG_RENAME_EXAMPLE compiled
2. Rename Trigger example
2.1 Get all triggers belong to a specified table
SELECT TABLE_NAME,TRIGGER_NAME FROM USER_TRIGGERS WHERE upper(TABLE_NAME) = 'ELECTRICITY_BILL';
TRIGGER_NAME | STATUS |
---|---|
ELECTRICITY_BILL | TRG_RENAME_EXAMPLE |
2.2 Rename a trigger.
ALTER TRIGGER trg_rename_example RENAME TO trg_name_updated; -- output -- Trigger TRG_RENAME_EXAMPLE altered.
2.3 Check the trigger name again.
SELECT TABLE_NAME,TRIGGER_NAME FROM USER_TRIGGERS WHERE upper(TABLE_NAME) = 'ELECTRICITY_BILL';
TRIGGER_NAME | STATUS |
---|---|
ELECTRICITY_BILL | TRG_NAME_UPDATED |
References
From:一号门
COMMENTS