G-4320
🆓Warning
Always label your loops.
Reason
It's a good alternative for comments to indicate the start and end of a named loop processing.
Example
Non-Compliant Example
declare i integer; co_min_value constant simple_integer := 1; co_max_value constant simple_integer := 10; co_increment constant simple_integer := 1; begin i := co_min_value; while (i <= co_max_value) loop i := i + co_increment; end loop; loop exit when true; end loop; for i in co_min_value..co_max_value loop sys.dbms_output.put_line(i); end loop; for r_employee in (select last_name from employees) loop sys.dbms_output.put_line(r_employee.last_name); end loop; end; /
Issues
Line | Column | Message |
---|---|---|
8 | 4 | |
11 | 8 | |
13 | 4 | |
15 | 8 | |
17 | 4 | |
20 | 8 | |
22 | 4 | |
25 | 8 |
★★★★★
Compliant Solution -
declare i integer; co_min_value constant simple_integer := 1; co_max_value constant simple_integer := 10; co_increment constant simple_integer := 1; begin i := co_min_value; <<while_loop>> while (i <= co_max_value) loop i := i + co_increment; end loop while_loop; <<basic_loop>> loop exit basic_loop when true; end loop basic_loop; <<for_loop>> for i in co_min_value..co_max_value loop sys.dbms_output.put_line(i); end loop for_loop; <<process_employees>> for r_employee in (select last_name from employees) loop sys.dbms_output.put_line(r_employee.last_name); end loop process_employees; end; /
References
- same as Trivadis G-4320
- similar to plsql:LabelledStatementUsageCheck
The scope of plsql:LabelledStatementUsageCheck is limited to nested loops only.