rspec/rules/S5870/plsql/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
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.
2023-05-25 14:18:12 +02:00

50 lines
1.3 KiB
Plaintext

== Why is this an issue?
Using ``++FORALL i IN x.first ... x++``.last or ``++FORALL i IN 1 ... x.count++`` might fail when indexed collections are sparse as Oracle tries to access non-existent element(s) of x. ``++FORALL i IN INDICES OF x++`` syntax will always work including sparse collections. Thus using ``++FORALL i IN INDICES OF x++`` should be preferred as it makes code more robust and easier to review.
=== Noncompliant code example
[source,sql]
----
FORALL i IN 1 .. l_tab.COUNT -- Non-Compliant
INSERT INTO forall_test VALUES l_tab(i);
FORALL i IN l_tab.first .. l_tab.last -- Non-Compliant
INSERT INTO forall_test VALUES l_tab(i);
----
=== Compliant solution
[source,sql]
----
FORALL i IN INDICES OF l_tab
INSERT INTO forall_test VALUES l_tab(i);
----
== Resources
* https://blogs.oracle.com/oraclemagazine/oracle-10g-adds-more-to-forall[Oracle 10g Adds More to FORALL]
* https://stevenfeuersteinonplsql.blogspot.com/2019/03/using-sparse-collections-with-forall.html[Using sparse collections with FORALL] - Steven Feuerstein
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Replace "IN ..." with "INDICES OF ..."
=== Highlighting
* ``++IN x.first ... x.last++``
* ``++1 ... x.count++``
endif::env-github,rspecator-view[]