Skip to content

G-2170: Never overload variables.

Major

Reliability

Reason

The readability of your code will be higher when you do not overload variables.

Example (bad)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
begin
   <<main>>
   declare
      co_main    constant user_objects.object_name%type := 'test_main';
      co_sub     constant user_objects.object_name%type := 'test_sub';
      co_sep     constant user_objects.object_name%type := ' - ';
      l_variable user_objects.object_name%type          := co_main;
   begin
      <<sub>>
      declare
         l_variable user_objects.object_name%type := co_sub;
      begin
         sys.dbms_output.put_line(l_variable
            || co_sep
            || main.l_variable);
      end sub;
   end main;
end;
/

Example (good)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
begin
   <<main>>
   declare
      co_main         constant user_objects.object_name%type := 'test_main';
      co_sub          constant user_objects.object_name%type := 'test_sub';
      co_sep          constant user_objects.object_name%type := ' - ';
      l_main_variable user_objects.object_name%type          := co_main;
   begin
      <<sub>>
      declare
         l_sub_variable user_objects.object_name%type := co_sub;
      begin
         sys.dbms_output.put_line(l_sub_variable
            || co_sep
            || l_main_variable);
      end sub;
   end main;
end;
/