rspec/rules/S1056/plsql/rule.adoc

44 lines
1.1 KiB
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
Compound triggers were introduced to ease the implementation of multiple triggers which need to work in cooperation.
Typically, a ``++FOR EACH ROW++`` trigger accumulates facts, and an ``++AFTER STATEMENT++`` trigger performs the actual changes.
The compound trigger can hold a state common to all the triggers it defines, thereby removing the need to use package variables. This approach is sometimes the only possible one, as when avoiding a mutating table ``++ORA-04091++`` error, or it can be used to get better performance.
However, there is no point in defining a compound trigger which contains only a single trigger, since there is no state to be shared. In such cases, a simple trigger should be used instead.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
CREATE OR REPLACE TRIGGER my_trigger -- Noncompliant; defines a single trigger
FOR INSERT ON my_table
COMPOUND TRIGGER
AFTER EACH ROW IS
BEGIN
DBMS_OUTPUT.PUT_LINE('New row inserted!');
END AFTER EACH ROW;
END;
/
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
CREATE OR REPLACE TRIGGER my_trigger
AFTER INSERT
ON my_table
FOR EACH ROW
BEGIN
DBMS_OUTPUT.PUT_LINE('New row inserted!');
END;
/
----