rspec/rules/S5870/plsql/rule.adoc

39 lines
1.2 KiB
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
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.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
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);
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
FORALL i IN INDICES OF l_tab
INSERT INTO forall_test VALUES l_tab(i);
----
2021-04-28 16:49:39 +02:00
== See
* 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)
include::message.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]