rspec/rules/S2481/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

64 lines
897 B
Plaintext

== Why is this an issue?
The ``++EXIT WHEN++`` syntax can exit a loop depending on a condition. It should be preferred to the more verbose and error-prone ``++IF ... THEN EXIT; END IF;++`` syntax.
=== Noncompliant code example
[source,sql]
----
SET SERVEROUTPUT ON
DECLARE
i PLS_INTEGER;
BEGIN
i := 0;
LOOP
IF i > 10 THEN -- Noncompliant
EXIT;
END IF;
DBMS_OUTPUT.PUT_LINE('i = ' || i);
i := i + 1;
END LOOP;
END;
/
----
=== Compliant solution
[source,sql]
----
SET SERVEROUTPUT ON
DECLARE
i PLS_INTEGER;
BEGIN
i := 0;
LOOP
EXIT WHEN i > 10;
DBMS_OUTPUT.PUT_LINE('i = ' || i);
i := i + 1;
END LOOP;
END;
/
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
This "IF...THEN...EXIT" should be replaced by "EXIT WHEN" statement.
endif::env-github,rspecator-view[]