Oracle PL/SQL – Rename Trigger

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

  1. Oracle – ALTER TRIGGER
  2. Oracle – PL/SQL Triggers
author image

Dhaval Dadhaniya

Dhaval Dadhaniya is a software engineer by profession and reader/writter by passion. He is working in a well reputed MNC as an applications Developer with 5 years of experience. He have good understanding and knowledge of Java, Database, Spring, Hibernate and exploring other technologies related to Software development. Befriend him on Facebook Read all published posts by

Comments

avatar