Triggers in PLSQL Detailed Darsh Shetty
Triggers in PLSQL Detailed Darsh Shetty
Definition:
A PL/SQL trigger is a stored procedure in Oracle that is automatically executed (or fired) when a specific event occurs.
General Syntax:
ON table_name
[WHEN (condition)]
BEGIN
END;
Types of Triggers:
1. BEFORE Triggers
2. AFTER Triggers
3. INSTEAD OF Triggers
4. Row-Level Triggers
5. Statement-Level Triggers
---
AFTER INSERT
ON table_name
BEGIN
END;
---
---
BEGIN
EXCEPTION
END;
END;
---
5. Write a PL/SQL Trigger to Log Changes in the Salary Column of the employees Table.
ON employees
BEGIN
END;
---
INSTEAD OF UPDATE
ON department_view
BEGIN
UPDATE departments
END;
---
1. Performance Impact
2. Debugging Complexity
3. Recursive Triggers
4. No Direct Invocation
---
---
---
10. What is the Purpose of the FOR EACH ROW Clause in a PL/SQL Trigger?
Makes a trigger a row-level trigger, executing once for every affected row.
---
11. Write a PL/SQL Trigger That Updates an audit_log Table After a Row is Deleted from the employees Table.
BEGIN
END;
---
12. How Would You Control the Execution Order of Multiple Triggers on the Same Table?
Oracle does not allow explicit control over trigger execution order. Combine logic into a single trigger.
---
BEGIN
END;
---
Best Practices: Use triggers only for critical tasks like auditing or validation.
---
BEGIN
END;