Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-30 · container image gvenzl/oracle-free:23-slim
OR REPLACE does not help here. Oracle replaces an existing trigger only when it is defined on the same table. If the name is already used by a trigger on another table, the statement stops with ORA-04095 and the old trigger stays as it was.
Look up the name in USER_TRIGGERS and check TABLE_NAME. Then decide: do you want a second trigger with its own name, or do you really want to move the trigger to the new table?
01Trigger copied for another table but the name was not changed
The trg_set_created trigger on ORDERS was copied to fill created_at on REFUNDS. Only the table name was edited, so CREATE OR REPLACE TRIGGER trg_set_created ... ON refunds points at a name that already belongs to ORDERS.
Setup
CREATE TABLE orders (order_id NUMBER PRIMARY KEY, created_at DATE);
CREATE TABLE refunds (refund_id NUMBER PRIMARY KEY, created_at DATE);
CREATE OR REPLACE TRIGGER trg_set_created BEFORE INSERT ON orders FOR EACH ROW
BEGIN
:NEW.created_at := SYSDATE;
END;
/Table created.
Table created.
Trigger created.CREATE OR REPLACE TRIGGER trg_set_created BEFORE INSERT ON refunds FOR EACH ROW
BEGIN
:NEW.created_at := SYSDATE;
END;
/CREATE OR REPLACE TRIGGER trg_set_created BEFORE INSERT ON refunds FOR EACH ROW
*
ERROR at line 1:
ORA-04095: trigger 'TRG_SET_CREATED' already exists on another table, cannot replace it
Help: https://docs.oracle.com/error-help/db/ora-04095/COLUMN trigger_name FORMAT A16
COLUMN table_name FORMAT A10
SELECT trigger_name, table_name FROM user_triggers;TRIGGER_NAME TABLE_NAME
---------------- ----------
TRG_SET_CREATED ORDERS
1 row selected.USER_TRIGGERS shows TRG_SET_CREATED on table ORDERS, not REFUNDS.
CREATE OR REPLACE TRIGGER refunds_bi BEFORE INSERT ON refunds FOR EACH ROW
BEGIN
:NEW.created_at := SYSDATE;
END;
/Trigger created.Give the new trigger its own name (refunds_bi). Both triggers now exist: REFUNDS_BI on REFUNDS and TRG_SET_CREATED on ORDERS.
COLUMN trigger_name FORMAT A16
COLUMN table_name FORMAT A10
SELECT trigger_name, table_name FROM user_triggers ORDER BY trigger_name;TRIGGER_NAME TABLE_NAME
---------------- ----------
REFUNDS_BI REFUNDS
TRG_SET_CREATED ORDERS
2 rows selected.02Moving a trigger to a new table with CREATE OR REPLACE
During a migration from ORDERS_OLD to ORDERS_NEW, the script tries to move orders_bu with CREATE OR REPLACE ... ON orders_new. Oracle does not move a trigger to another table this way.
Setup
CREATE TABLE orders_old (order_id NUMBER PRIMARY KEY, updated_at DATE);
CREATE TABLE orders_new (order_id NUMBER PRIMARY KEY, updated_at DATE);
CREATE OR REPLACE TRIGGER orders_bu BEFORE INSERT OR UPDATE ON orders_old FOR EACH ROW
BEGIN
:NEW.updated_at := SYSDATE;
END;
/Table created.
Table created.
Trigger created.CREATE OR REPLACE TRIGGER orders_bu BEFORE INSERT OR UPDATE ON orders_new FOR EACH ROW
BEGIN
:NEW.updated_at := SYSDATE;
END;
/CREATE OR REPLACE TRIGGER orders_bu BEFORE INSERT OR UPDATE ON orders_new FOR EACH ROW
*
ERROR at line 1:
ORA-04095: trigger 'ORDERS_BU' already exists on another table, cannot replace it
Help: https://docs.oracle.com/error-help/db/ora-04095/COLUMN trigger_name FORMAT A12
COLUMN table_name FORMAT A12
SELECT trigger_name, table_name, status FROM user_triggers;TRIGGER_NAME TABLE_NAME STATUS
------------ ------------ ------------------------------
ORDERS_BU ORDERS_OLD ENABLED
1 row selected.ORDERS_BU is still on ORDERS_OLD and ENABLED.
DROP TRIGGER orders_bu;
CREATE OR REPLACE TRIGGER orders_bu BEFORE INSERT OR UPDATE ON orders_new FOR EACH ROW
BEGIN
:NEW.updated_at := SYSDATE;
END;
/Trigger dropped.
Trigger created.DROP TRIGGER orders_bu first, then create it on orders_new. After that USER_TRIGGERS lists ORDERS_BU on ORDERS_NEW, and an insert into orders_new gets updated_at filled (SET).
INSERT INTO orders_new (order_id) VALUES (1);
COLUMN trigger_name FORMAT A12
COLUMN table_name FORMAT A12
SELECT trigger_name, table_name FROM user_triggers;
SELECT order_id, CASE WHEN updated_at IS NOT NULL THEN 'SET' END AS updated_at FROM orders_new;1 row created.
TRIGGER_NAME TABLE_NAME
------------ ------------
ORDERS_BU ORDERS_NEW
1 row selected.
ORDER_ID UPD
---------- ---
1 SET
1 row selected.FAQ
Why does CREATE OR REPLACE TRIGGER fail with ORA-04095?
Because a trigger with that name already exists on a different table. OR REPLACE only replaces a trigger on the same table.
How do I find which table a trigger belongs to?
Query SELECT trigger_name, table_name FROM user_triggers (or ALL_TRIGGERS for other schemas). TABLE_NAME shows the current table.
How do I move a trigger to another table?
Drop it and create it again: DROP TRIGGER name; then CREATE TRIGGER name ... ON new_table. If you want to keep the old one, use a new name instead.
What is the difference between ORA-04081 and ORA-04095?
ORA-04081 comes from CREATE TRIGGER without OR REPLACE when the name exists. ORA-04095 comes from CREATE OR REPLACE TRIGGER when the existing trigger is on another table.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0