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
begin 
   <<main>>
   declare
      k_main constant user_objects.object_name%type := 'test_main';
      k_sub constant user_objects.object_name%type := 'test_sub';
      k_sep constant user_objects.object_name%type := ' - ';
      l_variable user_objects.object_name%type := k_main;
   begin
      <<sub>>
      declare
         l_variable user_objects.object_name%type := k_sub;
      begin
         sys.dbms_output.put_line(l_variable || k_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
begin 
   <<main>>
   declare
      k_main constant user_objects.object_name%type := 'test_main';
      k_sub constant user_objects.object_name%type := 'test_sub';
      k_sep constant user_objects.object_name%type := ' - ';
      l_main_variable user_objects.object_name%type := k_main;
   begin
      <<sub>>
      declare
         l_sub_variable user_objects.object_name%type := k_sub;
      begin
         sys.dbms_output.put_line(l_sub_variable || k_sep || l_main_variable);
      end sub;
   end main;
end;
/