
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
60 lines
1.4 KiB
Plaintext
60 lines
1.4 KiB
Plaintext
== Why is this an issue?
|
|
|
|
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.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,sql]
|
|
----
|
|
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;
|
|
/
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,sql]
|
|
----
|
|
CREATE OR REPLACE TRIGGER my_trigger
|
|
AFTER INSERT
|
|
ON my_table
|
|
FOR EACH ROW
|
|
BEGIN
|
|
DBMS_OUTPUT.PUT_LINE('New row inserted!');
|
|
END;
|
|
/
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Replace this compound trigger with simple trigger.
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|