Avoid queries without an exception handling block
ZPA rule for PL/SQL and Oracle SQL · QueryWithoutExceptionHandling
A SELECT ... INTO must return exactly one row: with no row it raises NO_DATA_FOUND, and with more than one TOO_MANY_ROWS. When nothing handles them, the exception ends the caller's work with an error that does not say which lookup failed, often far from the query that caused it.
This rule reports a SELECT ... INTO whose block has no exception handler. A query written in an exception handler is not covered by the handlers next to it: only a block around it counts. A BULK COLLECT INTO is not reported, and neither is a query that always returns one row: a single aggregate (COUNT, SUM, AVG, MIN, MAX) without GROUP BY, HAVING, set operators, a row-limiting clause or MODEL. The rule does not check which exceptions the handler names.
With the strict parameter set to false, a handler of any enclosing block or subprogram covers the query.
Examples
create function rack_label(p_rack number) return varchar2 is
l_label rack.label%type;
begin
select label into l_label from rack where id = p_rack; -- Noncompliant
return l_label;
end;
create function rack_label(p_rack number) return varchar2 is
l_label rack.label%type;
begin
select label into l_label from rack where id = p_rack;
return l_label;
exception
when no_data_found then
return null;
end;