Sub topic 15
Listing, Disabling, Enabling, and Debugging Triggers
Assume you know basic SQL, PL/SQL, transactions, tables, views, and sequences. This chapter shows how to inspect trigger metadata, control whether triggers are active, and find compilation errors.
Listing Triggers
Oracle stores trigger metadata in data dictionary views. Use USER_TRIGGERS for triggers in your schema. The view includes the trigger name, timing and level, events, status, and source text.
SELECT trigger_name,
trigger_type,
triggering_event,
table_name,
status
FROM user_triggers
WHERE table_name = 'EMPLOYEES'
ORDER BY trigger_name;Object names are usually stored in uppercase unless they were created with quoted identifiers. A status of ENABLED means Oracle considers the trigger active. A status of DISABLED means Oracle does not fire it.
For triggers owned by other users, query ALL_TRIGGERS if your privileges allow it. A user with suitable administrative privileges can query DBA_TRIGGERS.
The TRIGGER_BODY column contains the PL/SQL body. To inspect a trigger's source in a readable form, use USER_SOURCE:
SELECT line, text
FROM user_source
WHERE name = 'EMPLOYEES_AUD'
AND type = 'TRIGGER'
ORDER BY line;Disabling and Enabling Triggers
Disable one trigger when you need to load data, investigate behavior, or temporarily stop a trigger from firing.
ALTER TRIGGER employees_aud DISABLE;
ALTER TRIGGER employees_aud ENABLE;You can disable or enable every trigger on a table:
ALTER TABLE employees DISABLE ALL TRIGGERS;
ALTER TABLE employees ENABLE ALL TRIGGERS;Disabling a trigger changes the database object configuration. It does not remove the trigger or undo data changes that already happened. Re-enable triggers promptly after a controlled maintenance operation. Otherwise, later changes might skip required validation or auditing.
Debugging Compilation Errors
A trigger can exist but have status INVALID if Oracle could not compile it. Check the status first, then inspect USER_ERRORS.
SELECT trigger_name, status
FROM user_triggers
WHERE trigger_name = 'EMPLOYEES_AUD';
SELECT name, type, line, position, text
FROM user_errors
WHERE name = 'EMPLOYEES_AUD'
AND type = 'TRIGGER'
ORDER BY sequence;The LINE and POSITION columns identify where Oracle found the problem. Fix the source, then compile the trigger again:
ALTER TRIGGER employees_aud COMPILE;In SQL*Plus or SQLcl, SHOW ERRORS is a client command that displays the latest compilation errors:
SHOW ERRORS TRIGGER employees_audCommon causes include misspelled column names, missing privileges on referenced objects, invalid PL/SQL syntax, and references to objects that were later changed or dropped. After recompiling, query USER_TRIGGERS again and confirm that the status is ENABLED.
Exercise
Which views show a trigger's current status and compilation errors?
Show answer
USERTRIGGERS shows the status and configuration. USERERRORS shows compilation errors, including their line and position.