Home

Labels redefined in inner scopes

Description

    The "Labels redefined in inner scopes" rule in PL/SQL states that labels defined in an outer scope cannot be redefined in an inner scope. This means that if a label is defined in an outer scope, it cannot be used again in an inner scope. This rule is important to ensure that labels are used consistently throughout a PL/SQL program. It also helps to avoid confusion when debugging and troubleshooting code.

Key Benefits

  • Improved readability: It allow for improved readability of code, making it easier to identify and understand the purpose of each line.
  • More efficient debugging: It make it easier to debug code, as the labels provide a clear indication of where the code is running.
  • Reduced complexity: It reduce the complexity of code, as the labels provide a clear indication of the purpose of each line.
  • Increased maintainability: It make it easier to maintain code, as the labels provide a clear indication of the purpose of each line.

 

Non-compliant Code Example

DECLARE
   abc INTEGER;
BEGIN
<<outerloop>>
   DECLARE
      abc INTEGER;
	
   BEGIN <<outerloop>>      --Non compliant code (Labels is re-defined in inner scopes)
      IF abc = outerloop.abc THEN  -- refers to global abc
         NULL;
      END IF;
   END outerloop;
END outerloop;

Compliant Code Example

DECLARE
   abc INTEGER;
BEGIN
<<outerloop>>
   DECLARE
      abc INTEGER;
	
   BEGIN <<innerloop>>      --Compliant code (Labels is not re-defined in inner scopes)
      IF abc = outerloop.abc THEN  -- refers to global abc
         NULL;
      END IF;
   END innerloop;
END outerloop;
Visual Expert 2024
 VEPLSQLRULE1