Skip to main content

Use cursor%NOTFOUND instead of NOT cursor%FOUND

ZPA rule for PL/SQL and Oracle SQL · NotFound

cursor%NOTFOUND is the negation of cursor%FOUND, null included: both are null before the first fetch, and both raise INVALID_CURSOR on an explicit cursor that is not open. Writing NOT cursor%FOUND adds an operator the reader has to undo to see the condition.

This rule reports NOT cursor%FOUND, for explicit cursors and for the implicit cursor (NOT SQL%FOUND).

Examples​

Noncompliant Code Example
loop
fetch c_crates into r_crate;
exit when not c_crates%found; -- Noncompliant
process_crate(r_crate);
end loop;
Compliant Solution
loop
fetch c_crates into r_crate;
exit when c_crates%notfound;
process_crate(r_crate);
end loop;