Unused local variables should be removed
ZPA rule for PL/SQL and Oracle SQL · UnusedVariable
A variable, constant or exception that is declared and never used is dead code. It makes the reader look for a use that does not exist, and it often remains after a change removed the code that used it.
This rule reports a local variable, constant or exception, or one of a package body, that no code of the file uses. Declarations of a package specification are not reported: other units may use them. A declaration is reported only when the analysis proves it unused: it is not reported when conditional compilation that may be compiled mentions its name, when a SQL name may read it unless a table has a column of that name, or when a syntax error, a substitution variable or code the analysis does not model is in its scope.
Examples
create procedure ship_order(p_order number, p_ready boolean) is
l_weight number; -- Noncompliant
l_attempts pls_integer := 0;
begin
while not p_ready and l_attempts < 3 loop
l_attempts := l_attempts + 1;
end loop;
dispatch(p_order);
end;
create procedure ship_order(p_order number, p_ready boolean) is
l_attempts pls_integer := 0;
begin
while not p_ready and l_attempts < 3 loop
l_attempts := l_attempts + 1;
end loop;
dispatch(p_order);
end;