G-4395: Avoid hard-coded upper or lower bound values with FOR loops.
Minor
Changeability, Maintainability
Reason
Your loop
statement uses a hard-coded value for either its upper or lower bounds. This creates a "weak link" in your program because it assumes that this value will never change. A better practice is to create a named constant (or function) and reference this named element instead of the hard-coded value.
Example (bad)
1 2 3 4 5 6 7 8 | begin <<output_loop>> for i in 1..5 loop sys.dbms_output.put_line(i); end loop output_loop; end; / |
Example (good)
1 2 3 4 5 6 7 8 9 10 11 | declare k_lower_bound constant simple_integer := 1; k_upper_bound constant simple_integer := 5; begin <<output_loop>> for i in k_lower_bound..k_upper_bound loop sys.dbms_output.put_line(i); end loop output_loop; end; / |