G-4387: Never use a FOR LOOP for a query that should return not more than one row.
Blocker
Reliability, Efficiency, Maintainability
Unsupported in db* CODECOP Validators
Without access to the Oracle Data Dictionary, we cannot determine the number of rows to be processed.
Reason
A for loop
can hide a too_many_rows
exception. The more complex a query is, the higher is the risk that more than one row will be processed.
This affects performance and can lead to a wrong result.
A for loop
can also hide a no_data_found
exception and the reader cannot determine whether this is intentional or not.
Example (bad)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Example (good)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|