Skip to content

G-7140: Always ensure that locally defined procedures or functions are referenced.

Major

Maintainability, Reliability

Reason

This can occur as the result of changes to code over time, but you should make sure that this situation does not reflect a problem. And you should remove the declaration to avoid maintenance errors in the future.

You should go through your programs and remove any part of your code that is no longer used. This is a relatively straightforward process for variables and named constants. Simply execute searches for a variable's name in that variable's scope. If you find that the only place it appears is in its declaration, delete the declaration.

There is never a better time to review all the steps you took, and to understand the reasons you took them, then immediately upon completion of your program. If you wait, you will find it particularly difficult to remember those parts of the program that were needed at one point, but were rendered unnecessary in the end.

Example (bad)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
create or replace package body my_package is
   procedure my_procedure is
      function my_func return number
         deterministic
      is
         co_true constant integer := 1;
      begin
         return co_true;
      end my_func;
   begin
      null;
   end my_procedure;
end my_package;
/

Example (good)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
create or replace package body my_package is
   procedure my_procedure is
      function my_func return number
         deterministic
      is
         co_true constant integer := 1;
      begin
         return co_true;
      end my_func;
   begin
      sys.dbms_output.put_line(my_func());
   end my_procedure;
end my_package;
/