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
Assigning to :NEW.column changes the row before it is written. That is only possible in a BEFORE ... FOR EACH ROW trigger on INSERT or UPDATE. In an AFTER trigger the row is already written, and a DELETE has no new row, so CREATE TRIGGER fails with ORA-04084 and the trigger is not created.
Below are two cases reproduced on Oracle 26ai Free and the fixes that were run.
01Calculated column set in an AFTER row trigger
The trigger was meant to fill amount with :NEW.qty * :NEW.price, but it was declared AFTER INSERT OR UPDATE ... FOR EACH ROW. Creating it failed with ORA-04084.
Changing only AFTER to BEFORE fixed it. Inserting qty 3, price 1500 stored amount 4500.
Setup
CREATE TABLE order_lines (line_id NUMBER PRIMARY KEY, qty NUMBER, price NUMBER, amount NUMBER);Table created.CREATE OR REPLACE TRIGGER order_lines_amt
AFTER INSERT OR UPDATE ON order_lines
FOR EACH ROW
BEGIN
:NEW.amount := :NEW.qty * :NEW.price;
END;
/CREATE OR REPLACE TRIGGER order_lines_amt
*
ERROR at line 1:
ORA-04084: cannot change NEW values for this trigger type
Help: https://docs.oracle.com/error-help/db/ora-04084/CREATE OR REPLACE TRIGGER order_lines_amt
BEFORE INSERT OR UPDATE ON order_lines
FOR EACH ROW
BEGIN
:NEW.amount := :NEW.qty * :NEW.price;
END;
/Trigger created.Use BEFORE to change the row being written. Use AFTER for work that only reads :NEW, such as writing to another table.
INSERT INTO order_lines (line_id, qty, price) VALUES (1, 3, 1500);
SELECT line_id, qty, price, amount FROM order_lines;
ROLLBACK;1 row created.
LINE_ID QTY PRICE AMOUNT
---------- ---------- ---------- ----------
1 3 1500 4500
1 row selected.
Rollback complete.02Setting :NEW in a DELETE trigger (to record who deleted)
A BEFORE DELETE ... FOR EACH ROW trigger tried :NEW.deleted_by := USER. A deleted row has no new values, so creating the trigger failed with ORA-04084.
The trigger was changed to insert :OLD.cust_id, :OLD.name and USER into a separate customers_deleted table. Deleting customer 1 left the row (1, Kim, LAB_A) there.
Setup
CREATE TABLE customers (cust_id NUMBER PRIMARY KEY, name VARCHAR2(30), deleted_by VARCHAR2(30));
CREATE TABLE customers_deleted (cust_id NUMBER, name VARCHAR2(30), deleted_by VARCHAR2(30), deleted_at DATE);
INSERT INTO customers VALUES (1, 'Kim', NULL);
COMMIT;Table created.
Table created.
1 row created.
Commit complete.CREATE OR REPLACE TRIGGER customers_bd
BEFORE DELETE ON customers
FOR EACH ROW
BEGIN
:NEW.deleted_by := USER;
END;
/CREATE OR REPLACE TRIGGER customers_bd
*
ERROR at line 1:
ORA-04084: cannot change NEW values for this trigger type
Help: https://docs.oracle.com/error-help/db/ora-04084/CREATE OR REPLACE TRIGGER customers_bd
BEFORE DELETE ON customers
FOR EACH ROW
BEGIN
INSERT INTO customers_deleted VALUES (:OLD.cust_id, :OLD.name, USER, SYSDATE);
END;
/Trigger created.DELETE FROM customers WHERE cust_id = 1;
SELECT cust_id, name, deleted_by FROM customers_deleted;
ROLLBACK;1 row deleted.
CUST_ID NAME DELETED_BY
---------- ------------------------------ ------------------------------
1 Kim LAB_A
1 row selected.
Rollback complete.FAQ
Why can't I change :NEW in an AFTER trigger?
The row has already been written when an AFTER trigger runs. Change :NEW in a BEFORE row trigger instead; in the first case only AFTER → BEFORE was needed.
How do I record who deleted a row in Oracle?
In a DELETE trigger there is no :NEW. Write :OLD values and USER to a separate log table in the trigger, as in the second case.
Is the trigger created when ORA-04084 occurs?
No. CREATE TRIGGER stops with the error. Change the trigger type or the logic and run CREATE OR REPLACE TRIGGER again, as in both cases on this page.
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