Oracle 23.26PL/SQLLab-verified · 2026-12-01

ORA-04098: trigger is invalid and failed re-validation

The INSERT fired a trigger that had become invalid, and Oracle could not recompile it.

Oracle AI Database 26ai Free 23.26.3.0.0
ORA-04098: trigger 'LAB_A.ORDERS_BI' is invalid and failed re-validation

Jump to a cause

  1. 01A column the trigger uses was renamed
  2. 02A table the trigger writes to was dropped
  3. 03The sequence that filled the ID was dropped
  4. 04The privilege on another schema's table was revoked
  5. 05The trigger was created with a compilation error from the start
  6. 06A function called by the trigger got a new parameter

Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-12-01 · container image gvenzl/oracle-free:23-slim

A trigger depends on the tables, columns, privileges and functions it uses. When one of them changes, the trigger becomes INVALID. On the next DML Oracle tries to recompile it; if that fails, the DML itself fails with ORA-04098, and the message only names the trigger: trigger 'LAB_A.ORDERS_BI' is invalid and failed re-validation.

The real reason is in the trigger's compile errors. Run SHOW ERRORS TRIGGER <name> in SQL*Plus (or query user_errors) right away. Every case below shows that output next to the error.

01A column the trigger uses was renamed

The trigger set :NEW.created_at := SYSDATE, and then the column was renamed with ALTER TABLE orders RENAME COLUMN created_at TO order_date. The INSERT failed with ORA-04098, and SHOW ERRORS showed PLS-00049: bad bind variable 'NEW.CREATED_AT'.

The trigger body was rewritten with CREATE OR REPLACE TRIGGER to use :NEW.order_date. The INSERT then worked and order_date was filled in.

Setup
Setuprun as lab_a
CREATE TABLE orders (order_id NUMBER, amount NUMBER, created_at DATE);
CREATE OR REPLACE TRIGGER orders_bi
BEFORE INSERT ON orders
FOR EACH ROW
BEGIN
  :NEW.created_at := SYSDATE;
END;
/
ALTER TABLE orders RENAME COLUMN created_at TO order_date;
OUTPUT
Table created.


Trigger created.


Table altered.
Reproducerun as lab_a
INSERT INTO orders (order_id, amount) VALUES (1, 100);
SHOW ERRORS TRIGGER orders_bi
✕ ERROR
INSERT INTO orders (order_id, amount) VALUES (1, 100)
            *
ERROR at line 1:
ORA-04098: trigger 'LAB_A.ORDERS_BI' is invalid and failed re-validation
Help: https://docs.oracle.com/error-help/db/ora-04098/


Errors for TRIGGER ORDERS_BI:

LINE/COL ERROR
-------- -----------------------------------------------------------------
2/3      PLS-00049: bad bind variable 'NEW.CREATED_AT'
Check the causerun as lab_a
COLUMN object_name FORMAT A12
SELECT object_name, status FROM user_objects WHERE object_name = 'ORDERS_BI';
COLUMN column_name FORMAT A12
SELECT column_name FROM user_tab_columns WHERE table_name = 'ORDERS' ORDER BY column_id;
OUTPUT
OBJECT_NAME  STATUS
------------ ------------------------------
ORDERS_BI    INVALID

1 row selected.


COLUMN_NAME
------------
ORDER_ID
AMOUNT
ORDER_DATE

3 rows selected.

The trigger ORDERS_BI is INVALID, and the column list of ORDERS shows ORDER_DATE but no CREATED_AT. The trigger still refers to the old column name.

Fixrun as lab_a
CREATE OR REPLACE TRIGGER orders_bi
BEFORE INSERT ON orders
FOR EACH ROW
BEGIN
  :NEW.order_date := SYSDATE;
END;
/
OUTPUT
Trigger created.

Recompiling alone cannot fix this, because the trigger code still names the old column. The code itself has to change.

After the fixrun as lab_a
COLUMN order_date_set FORMAT A14
INSERT INTO orders (order_id, amount) VALUES (1, 100);
SELECT order_id, amount, CASE WHEN order_date IS NOT NULL THEN 'SET' END AS order_date_set FROM orders;
✓ SUCCESS
1 row created.


  ORDER_ID     AMOUNT ORDER_DATE_SET
---------- ---------- --------------
         1        100 SET

1 row selected.

02A table the trigger writes to was dropped

The trigger copied each new order into orders_log, and orders_log was then dropped. SHOW ERRORS showed PL/SQL: ORA-00942: table or view does not exist on line 2.

After creating orders_log again and running ALTER TRIGGER orders_ai COMPILE;, user_objects showed the trigger as VALID. The INSERT worked and the log row was written.

Setup
Setuprun as lab_a
CREATE TABLE orders (order_id NUMBER, amount NUMBER);
CREATE TABLE orders_log (order_id NUMBER, logged_at DATE);
CREATE OR REPLACE TRIGGER orders_ai
AFTER INSERT ON orders
FOR EACH ROW
BEGIN
  INSERT INTO orders_log VALUES (:NEW.order_id, SYSDATE);
END;
/
DROP TABLE orders_log PURGE;
OUTPUT
Table created.


Table created.


Trigger created.


Table dropped.
Reproducerun as lab_a
INSERT INTO orders VALUES (1, 100);
SHOW ERRORS TRIGGER orders_ai
✕ ERROR
INSERT INTO orders VALUES (1, 100)
            *
ERROR at line 1:
ORA-04098: trigger 'LAB_A.ORDERS_AI' is invalid and failed re-validation
Help: https://docs.oracle.com/error-help/db/ora-04098/


Errors for TRIGGER ORDERS_AI:

LINE/COL ERROR
-------- -----------------------------------------------------------------
2/3      PL/SQL: SQL Statement ignored
2/15     PL/SQL: ORA-00942: table or view does not exist
Check the causerun as lab_a
COLUMN object_name FORMAT A12
SELECT object_name, status FROM user_objects WHERE object_name = 'ORDERS_AI';
SELECT COUNT(*) AS orders_log_exists FROM user_tables WHERE table_name = 'ORDERS_LOG';
OUTPUT
OBJECT_NAME  STATUS
------------ ------------------------------
ORDERS_AI    INVALID

1 row selected.


ORDERS_LOG_EXISTS
-----------------
                0

1 row selected.

ORDERS_AI is INVALID, and ORDERS_LOG_EXISTS is 0: the table the trigger inserts into no longer exists.

Fixrun as lab_a
CREATE TABLE orders_log (order_id NUMBER, logged_at DATE);
ALTER TRIGGER orders_ai COMPILE;
SELECT object_name, status FROM user_objects WHERE object_type = 'TRIGGER';
OUTPUT
Table created.


Trigger altered.


OBJECT_NAME                    STATUS
------------------------------ ------------------------------
ORDERS_AI                      VALID

1 row selected.

Here the trigger code was fine, so bringing the table back and compiling was enough.

After the fixrun as lab_a
INSERT INTO orders VALUES (1, 100);
SELECT order_id FROM orders_log;
✓ SUCCESS
1 row created.


  ORDER_ID
----------
         1

1 row selected.

03The sequence that filled the ID was dropped

This was the usual ID trigger that fills order_id from orders_seq.NEXTVAL, and orders_seq was dropped. The trigger code did not change, yet the INSERT failed with ORA-04098, and SHOW ERRORS showed PLS-00201: identifier 'ORDERS_SEQ.NEXTVAL' must be declared.

The highest existing ID was 2, so we recreated it with CREATE SEQUENCE orders_seq START WITH 3; and ran ALTER TRIGGER orders_bi COMPILE;. The trigger became VALID, and the next INSERT got ORDER_ID 3.

Setup
Setuprun as lab_a
CREATE TABLE orders (order_id NUMBER PRIMARY KEY, amount NUMBER);
CREATE SEQUENCE orders_seq;
CREATE OR REPLACE TRIGGER orders_bi
BEFORE INSERT ON orders
FOR EACH ROW
WHEN (NEW.order_id IS NULL)
BEGIN
  :NEW.order_id := orders_seq.NEXTVAL;
END;
/
INSERT INTO orders (amount) VALUES (100);
INSERT INTO orders (amount) VALUES (200);
COMMIT;
DROP SEQUENCE orders_seq;
OUTPUT
Table created.


Sequence created.


Trigger created.


1 row created.


1 row created.


Commit complete.


Sequence dropped.
Reproducerun as lab_a
INSERT INTO orders (amount) VALUES (300);
SHOW ERRORS TRIGGER orders_bi
✕ ERROR
INSERT INTO orders (amount) VALUES (300)
            *
ERROR at line 1:
ORA-04098: trigger 'LAB_A.ORDERS_BI' is invalid and failed re-validation
Help: https://docs.oracle.com/error-help/db/ora-04098/


Errors for TRIGGER ORDERS_BI:

LINE/COL ERROR
-------- -----------------------------------------------------------------
2/3      PL/SQL: Statement ignored
2/20     PLS-00201: identifier 'ORDERS_SEQ.NEXTVAL' must be declared
Check the causerun as lab_a
COLUMN object_name FORMAT A12
SELECT object_name, status FROM user_objects WHERE object_name = 'ORDERS_BI';
SELECT COUNT(*) AS orders_seq_exists FROM user_sequences WHERE sequence_name = 'ORDERS_SEQ';
SELECT MAX(order_id) AS max_order_id FROM orders;
OUTPUT
OBJECT_NAME  STATUS
------------ ------------------------------
ORDERS_BI    INVALID

1 row selected.


ORDERS_SEQ_EXISTS
-----------------
                0

1 row selected.


MAX_ORDER_ID
------------
           2

1 row selected.

ORDERS_BI is INVALID and ORDERS_SEQ_EXISTS is 0: the sequence the trigger uses is gone. MAX_ORDER_ID (2) tells you where the recreated sequence should start.

Fixrun as lab_a
CREATE SEQUENCE orders_seq START WITH 3;
ALTER TRIGGER orders_bi COMPILE;
COLUMN object_name FORMAT A12
SELECT object_name, status FROM user_objects WHERE object_name = 'ORDERS_BI';
OUTPUT
Sequence created.


Trigger altered.


OBJECT_NAME  STATUS
------------ ------------------------------
ORDERS_BI    VALID

1 row selected.

A plain CREATE SEQUENCE starts at 1 and can collide with existing IDs. Check MAX(order_id) first and start just above it.

After the fixrun as lab_a
INSERT INTO orders (amount) VALUES (300);
SELECT order_id, amount FROM orders ORDER BY order_id;
✓ SUCCESS
1 row created.


  ORDER_ID     AMOUNT
---------- ----------
         1        100
         2        200
         3        300

3 rows selected.

04The privilege on another schema's table was revoked

LAB_A's trigger inserted into lab_b.audit_log, using an INSERT privilege from LAB_B. When LAB_B revoked it, the trigger became invalid. SHOW ERRORS showed ORA-00942: table or view "LAB_B"."AUDIT_LOG" does not exist. The table still existed; without the privilege it simply could not be seen.

LAB_B granted INSERT again, LAB_A ran ALTER TRIGGER orders_audit COMPILE;, and the INSERT worked.

Setup
Setuprun as lab_b
CREATE TABLE audit_log (table_name VARCHAR2(30), logged_at DATE);
GRANT INSERT ON audit_log TO lab_a;
OUTPUT
Table created.


Grant succeeded.
Setuprun as lab_a
CREATE TABLE orders (order_id NUMBER, amount NUMBER);
CREATE OR REPLACE TRIGGER orders_audit
AFTER INSERT ON orders
BEGIN
  INSERT INTO lab_b.audit_log VALUES ('ORDERS', SYSDATE);
END;
/
OUTPUT
Table created.


Trigger created.
Setuprun as lab_b
REVOKE INSERT ON audit_log FROM lab_a;
OUTPUT
Revoke succeeded.
Reproducerun as lab_a
INSERT INTO orders VALUES (1, 100);
SHOW ERRORS TRIGGER orders_audit
✕ ERROR
INSERT INTO orders VALUES (1, 100)
                  *
ERROR at line 1:
ORA-04098: trigger 'LAB_A.ORDERS_AUDIT' is invalid and failed re-validation
Help: https://docs.oracle.com/error-help/db/ora-04098/


Errors for TRIGGER ORDERS_AUDIT:

LINE/COL ERROR
-------- -----------------------------------------------------------------
2/3      PL/SQL: SQL Statement ignored
2/21     PL/SQL: ORA-00942: table or view "LAB_B"."AUDIT_LOG" does not
         exist
Check the causerun as lab_a
COLUMN object_name FORMAT A14
SELECT object_name, status FROM user_objects WHERE object_name = 'ORDERS_AUDIT';
COLUMN owner FORMAT A8
COLUMN table_name FORMAT A10
COLUMN privilege FORMAT A10
SELECT owner, table_name, privilege FROM user_tab_privs WHERE table_name = 'AUDIT_LOG';
OUTPUT
OBJECT_NAME    STATUS
-------------- ------------------------------
ORDERS_AUDIT   INVALID

1 row selected.


no rows selected

ORDERS_AUDIT is INVALID, and USER_TAB_PRIVS returns no rows for AUDIT_LOG: LAB_A no longer has the INSERT privilege the trigger needs.

Fixrun as lab_b
GRANT INSERT ON audit_log TO lab_a;
OUTPUT
Grant succeeded.
Fixrun as lab_a
ALTER TRIGGER orders_audit COMPILE;
OUTPUT
Trigger altered.

ORA-00942 in the trigger errors does not always mean the table is gone. For a table in another schema, check the grant first.

After the fixrun as lab_a
INSERT INTO orders VALUES (1, 100);
COMMIT;
✓ SUCCESS
1 row created.


Commit complete.

05The trigger was created with a compilation error from the start

The trigger body was missing ; after :NEW.qty := NVL(:NEW.qty, 0). SQL*Plus only printed "Warning: Trigger created with compilation errors.", the script went on, and the next INSERT failed with ORA-04098. The trigger exists but cannot run, so every INSERT into the table fails.

user_objects showed STOCK_BI as INVALID and user_errors pointed at line 3, position 1 (the END right after the line missing ;). After recreating the trigger with the semicolon, the INSERT worked and qty was set to 0.

Setup
Setuprun as lab_a
CREATE TABLE stock (item_id NUMBER PRIMARY KEY, qty NUMBER);
OUTPUT
Table created.
Reproducerun as lab_a
CREATE OR REPLACE TRIGGER stock_bi BEFORE INSERT ON stock FOR EACH ROW
BEGIN
  :NEW.qty := NVL(:NEW.qty, 0)
END;
/
INSERT INTO stock VALUES (1, NULL);
✕ ERROR
Warning: Trigger created with compilation errors.

INSERT INTO stock VALUES (1, NULL)
            *
ERROR at line 1:
ORA-04098: trigger 'LAB_A.STOCK_BI' is invalid and failed re-validation
Help: https://docs.oracle.com/error-help/db/ora-04098/
Check the causerun as lab_a
COLUMN object_name FORMAT A10
SELECT object_name, status FROM user_objects WHERE object_name = 'STOCK_BI';
SELECT line, position FROM user_errors WHERE name = 'STOCK_BI' ORDER BY sequence;
OUTPUT
OBJECT_NAM STATUS
---------- ------------------------------
STOCK_BI   INVALID

1 row selected.


      LINE   POSITION
---------- ----------
         3          1

1 row selected.

STOCK_BI is INVALID, and USER_ERRORS points to line 3, column 1. That is where the compile error is.

Fixrun as lab_a
CREATE OR REPLACE TRIGGER stock_bi BEFORE INSERT ON stock FOR EACH ROW
BEGIN
  :NEW.qty := NVL(:NEW.qty, 0);
END;
/
OUTPUT
Trigger created.
After the fixrun as lab_a
INSERT INTO stock VALUES (1, NULL);
SELECT item_id, qty FROM stock;
✓ SUCCESS
1 row created.


   ITEM_ID        QTY
---------- ----------
         1          0

1 row selected.

06A function called by the trigger got a new parameter

The trigger sets :NEW.tax := calc_tax(:NEW.amount);. Later calc_tax was replaced with a two-parameter version (p_amount, p_rate). The function itself compiled fine, but the next INSERT failed with ORA-04098, and SHOW ERRORS showed PLS-00306: wrong number or types of arguments in call to 'CALC_TAX' at line 2.

After changing the trigger to calc_tax(:NEW.amount, 0.1) the INSERT worked and TAX was 1500.

Setup
Setuprun as lab_a
CREATE TABLE orders (order_id NUMBER, amount NUMBER, tax NUMBER);
CREATE OR REPLACE FUNCTION calc_tax (p_amount NUMBER) RETURN NUMBER IS
BEGIN
  RETURN ROUND(p_amount * 0.1);
END;
/
CREATE OR REPLACE TRIGGER orders_tax_bi
BEFORE INSERT ON orders
FOR EACH ROW
BEGIN
  :NEW.tax := calc_tax(:NEW.amount);
END;
/
CREATE OR REPLACE FUNCTION calc_tax (p_amount NUMBER, p_rate NUMBER) RETURN NUMBER IS
BEGIN
  RETURN ROUND(p_amount * p_rate);
END;
/
OUTPUT
Table created.


Function created.


Trigger created.


Function created.
Reproducerun as lab_a
INSERT INTO orders (order_id, amount) VALUES (1, 15000);
SHOW ERRORS TRIGGER orders_tax_bi
✕ ERROR
INSERT INTO orders (order_id, amount) VALUES (1, 15000)
            *
ERROR at line 1:
ORA-04098: trigger 'LAB_A.ORDERS_TAX_BI' is invalid and failed re-validation
Help: https://docs.oracle.com/error-help/db/ora-04098/


Errors for TRIGGER ORDERS_TAX_BI:

LINE/COL ERROR
-------- -----------------------------------------------------------------
2/3      PL/SQL: Statement ignored
2/15     PLS-00306: wrong number or types of arguments in call to
         'CALC_TAX'
Check the causerun as lab_a
COLUMN object_name FORMAT A14
SELECT object_name, object_type, status FROM user_objects WHERE object_name IN ('ORDERS_TAX_BI', 'CALC_TAX') ORDER BY object_name;
COLUMN argument_name FORMAT A10
SELECT argument_name, position, data_type FROM user_arguments WHERE object_name = 'CALC_TAX' AND argument_name IS NOT NULL ORDER BY position;
OUTPUT
OBJECT_NAME    OBJECT_TYPE                    STATUS
-------------- ------------------------------ ------------------------------
CALC_TAX       FUNCTION                       VALID
ORDERS_TAX_BI  TRIGGER                        INVALID

2 rows selected.


ARGUMENT_N   POSITION DATA_TYPE
---------- ---------- ------------------------------
P_AMOUNT            1 NUMBER
P_RATE              2 NUMBER

2 rows selected.

CALC_TAX is VALID but the trigger is INVALID. The function now takes two arguments, P_AMOUNT and P_RATE, while the trigger passes one.

Fixrun as lab_a
CREATE OR REPLACE TRIGGER orders_tax_bi
BEFORE INSERT ON orders
FOR EACH ROW
BEGIN
  :NEW.tax := calc_tax(:NEW.amount, 0.1);
END;
/
OUTPUT
Trigger created.

Before changing the parameters of a shared function, check who calls it (user_dependencies). Adding the new parameter with a DEFAULT keeps old calls working.

After the fixrun as lab_a
INSERT INTO orders (order_id, amount) VALUES (1, 15000);
SELECT order_id, amount, tax FROM orders;
✓ SUCCESS
1 row created.


  ORDER_ID     AMOUNT        TAX
---------- ---------- ----------
         1      15000       1500

1 row selected.

FAQ

What does ORA-04098 trigger is invalid and failed re-validation mean?

The DML fired a trigger that was INVALID, Oracle tried to recompile it, and the compile failed. The DML is rejected.

How do I find why the trigger is invalid?

Run SHOW ERRORS TRIGGER <name> in SQL*Plus, or SELECT line, position, text FROM user_errors WHERE name = '<NAME>';. The real error (PLS-00049, ORA-00942 and so on) is there.

How do I recompile an invalid trigger?

ALTER TRIGGER <name> COMPILE; after fixing what it depends on. Check the result with SELECT object_name, status FROM user_objects WHERE object_type = 'TRIGGER';.

Why does a plain INSERT fail because of a trigger?

A trigger runs as part of the statement. If the trigger cannot be compiled, the INSERT that fires it cannot run either.

Why does every INSERT fail after I created a trigger?

The trigger was probably created with compilation errors. SQL*Plus only shows a warning, but the invalid trigger makes each INSERT fail with ORA-04098. Check user_errors (or SHOW ERRORS) and recreate it.

Why did my trigger become invalid when I changed a function?

The trigger still calls the function the old way. In the lab calc_tax got a second parameter, and the trigger failed with PLS-00306 until the call passed both values.

ORA-04098 after dropping a sequence used by an ID trigger

The trigger that sets the ID from seq.NEXTVAL is now invalid. SHOW ERRORS TRIGGER name shows PLS-00201 ... NEXTVAL must be declared. Recreate the sequence with START WITH one above MAX(id), run ALTER TRIGGER ... COMPILE, and inserts work again.

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