G-1020
🆓Warning
Always have a matching loop or block label.
Reason
Use a label directly in front of loops and nested anonymous blocks:
- To give a name to that portion of code and thereby self-document what it is doing.
- So that you can repeat that name with the
end
statement of that block or loop.
The PL/SQL compiler allows different start and end labels, but this makes the code harder to read and understand.
Example
Non-Compliant Example
declare i simple_integer := 1; begin <<prepare_data>> begin null; end data_preparation; <<process_with_while_loop>> while (i <= 10) loop i := i + 1; end loop while_loop; <<process_with_basic_loop>> loop exit process_with_basic_loop when true; end loop basic_loop; <<process_with_for_loop>> for i in 1..10 loop sys.dbms_output.put_line(i); end loop for_loop; <<process_with_cursor_for_loop>> for r in (select table_name from user_tables) loop sys.dbms_output.put_line(r.table_name); end loop cursor_for_loop; end; /
Issues
Line | Column | Message |
---|---|---|
7 | 8 | |
13 | 13 | |
18 | 13 | |
23 | 13 | |
28 | 13 |
★★★★★
Compliant Solution -
declare i simple_integer := 1; begin <<prepare_data>> begin null; end prepare_data; <<process_with_while_loop>> while (i <= 10) loop i := i + 1; end loop process_with_while_loop; <<process_with_basic_loop>> loop exit process_with_basic_loop when true; end loop process_with_basic_loop; <<process_with_for_loop>> for i in 1..10 loop sys.dbms_output.put_line(i); end loop process_with_for_loop; <<process_with_cursor_for_loop>> for r in (select table_name from user_tables) loop sys.dbms_output.put_line(r.table_name); end loop process_with_cursor_for_loop; end; /
Parameters
Use parameters to customize the rule to your needs.
Parameter | Description | Default Value |
---|---|---|
DisableAllQuickFix | Comma-separated ist of rules for which a quick fix should not be applied to all the problems in a file. | Core G-3130 |
References
- similar to plsql:plsql:BlockUnlabeledEndCheck
The scope of plsql:plsql:BlockUnlabeledEndCheck is missing block end labels.
- similar to plsql:LabelStartEndMatchBlockCheck
The scope of plsql:LabelStartEndMatchBlockCheck is mismatches of block start and end labels.
- similar to plsql:LoopUnlabeledEndCheck
The scope of plsql:LoopUnlabeledEndCheck is missing loop end labels.
- same as Trivadis G-1020
- similar to plsql:LabelStartEndMatchLoopCheck
The scope of plsql:LabelStartEndMatchLoopCheck is mismatches of loop start and end labels.