ORA-04075: Invalid Trigger Specification — Causes and Fixes
ORA-04075 is thrown by Oracle when a trigger definition contains an invalid combination of trigger type, event, target object, or level specification. This error prevents the trigger from being created or compiled successfully. Understanding the exact rules around trigger specifications is essential to resolving this error quickly.
Top 3 Causes and Fixes
1. Applying INSTEAD OF Trigger to a Table
INSTEAD OF triggers are exclusively designed for views, not tables. Attempting to create one on a table immediately triggers ORA-04075.
Wrong (causes ORA-04075):
-- INSTEAD OF on a table → ORA-04075
CREATE OR REPLACE TRIGGER trg_bad_instead
INSTEAD OF INSERT ON employees -- employees is a TABLE, not a VIEW
FOR EACH ROW
BEGIN
NULL;
END;
/
Fix — Use INSTEAD OF only on a VIEW:
-- Create a view first
CREATE OR REPLACE VIEW emp_view AS
SELECT employee_id, first_name, last_name
FROM employees;
-- Apply INSTEAD OF to the view
CREATE OR REPLACE TRIGGER trg_emp_view_insert
INSTEAD OF INSERT ON emp_view
FOR EACH ROW
BEGIN
INSERT INTO employees (employee_id, first_name, last_name)
VALUES (:NEW.employee_id, :NEW.first_name, :NEW.last_name);
END;
/
Fix — Use BEFORE/AFTER for tables:
CREATE OR REPLACE TRIGGER trg_emp_before_insert
BEFORE INSERT ON employees
FOR EACH ROW
BEGIN
IF :NEW.salary IS NULL THEN
:NEW.salary := 3000;
END IF;
END;
/
2. Mixing Incompatible Trigger Type and Event
Oracle triggers support three categories of events: DML (INSERT/UPDATE/DELETE), DDL (CREATE/ALTER/DROP), and Database Events (LOGON/LOGOFF/STARTUP). Combining the wrong trigger type with an incompatible event causes ORA-04075.
Wrong (causes ORA-04075):
-- INSTEAD OF with a DDL event → ORA-04075
CREATE OR REPLACE TRIGGER trg_bad_ddl
INSTEAD OF CREATE ON SCHEMA
BEGIN
NULL;
END;
/
Fix — Use BEFORE/AFTER for DDL events:
CREATE OR REPLACE TRIGGER trg_ddl_audit
BEFORE CREATE ON SCHEMA
BEGIN
INSERT INTO ddl_audit_log (event_type, object_name, event_date)
VALUES (ora_sysevent, ora_dict_obj_name, SYSDATE);
COMMIT;
END;
/
Fix — Correct Database Event trigger:
CREATE OR REPLACE TRIGGER trg_logon_track
AFTER LOGON ON DATABASE
BEGIN
INSERT INTO logon_log (username, logon_time)
VALUES (USER, SYSDATE);
COMMIT;
END;
/
3. Using FOR EACH ROW with DDL or Database Event Triggers
FOR EACH ROW is valid only for DML triggers (row-level). Adding it to a DDL or database event trigger will immediately raise ORA-04075.
Wrong (causes ORA-04075):
-- FOR EACH ROW on a DDL trigger → ORA-04075
CREATE OR REPLACE TRIGGER trg_bad_row
AFTER CREATE ON SCHEMA
FOR EACH ROW -- Not allowed here
BEGIN
NULL;
END;
/
Fix — Remove FOR EACH ROW from DDL triggers:
CREATE OR REPLACE TRIGGER trg_ddl_log
AFTER CREATE ON SCHEMA
BEGIN
INSERT INTO ddl_log (obj_name, event_type, created_by, event_date)
VALUES (ora_dict_obj_name, ora_sysevent, USER, SYSDATE);
COMMIT;
END;
/
Quick Validation After Trigger Creation
Always verify your trigger compiled successfully:
-- Check trigger status
SELECT trigger_name, trigger_type, triggering_event, status
FROM user_triggers
WHERE trigger_name = 'YOUR_TRIGGER_NAME';
-- Check for compilation errors
SELECT name, line, position, text
FROM user_errors
WHERE type = 'TRIGGER'
ORDER BY name, line;
Prevention Tips
- Follow the compatibility matrix: INSTEAD OF → VIEW only; BEFORE/AFTER → TABLE or VIEW; DDL/DB Event triggers → no FOR EACH ROW. Keep this as a team reference to avoid mismatches before writing a single line.
-
Include trigger validation in your deployment pipeline: Add a post-deployment script that queries
USER_TRIGGERSandUSER_ERRORSto catch invalid triggers before they reach production. Catching ORA-04075 in dev costs seconds; catching it in production costs hours.
Related Errors
- ORA-04076 — Invalid NEW or OLD specification inside trigger body
- ORA-04077 — WHEN clause used on a statement-level trigger
- ORA-04079 — General invalid trigger specification (syntax-level variant)
📖 Want a more detailed guide?
Check out the full in-depth version (Korean) on oraerror.com — includes detailed analysis, additional SQL examples, and prevention tips.
Top comments (0)