Home

Unused labels should be removed

Description

    The rule of "Unused Labels should be removed" in PL/SQL code states that any labels that are not used in the code should be removed. This is important because unused labels can lead to confusion and can make the code difficult to read and understand. Additionally, having too many labels can slow down the performance of the code. Therefore, it is important to ensure that all unused labels are removed from the code to improve readability and performance.

Key Benefits

  • Reduced clutter: Unused labels should be removed, reducing the amount of unnecessary clutter in the code.
  • Improved readability: Removing unused labels makes the code easier to read and understand.
  • Less confusion: Unused labels can cause confusion, as they may not be immediately obvious to the reader.
  • Better performance: Unused labels can slow down the performance of the code, as they take up extra space and processing time.

 

Non-compliant Code Example

DECLARE 
   id customers.id%type; 
   name customer.name%type; 
   address customers.address%type; 
   CURSOR customers_c is 
      SELECT id, name, address FROM customers; 
BEGIN 
   OPEN customers_c; 
   <<INNER_LOOP>>         --Non compliant code (Unused labels)
   LOOP 
   FETCH customers_c into id, name, address; 
      EXIT WHEN customers_c%notfound; 
      dbms_output.put_line(id || ' ' || name || ' ' || address); 
   END LOOP INNERONE_LOOP; 
   CLOSE customers_c; 
END; 

Compliant Code Example

DECLARE 
   id customers.id%type; 
   name customer.name%type; 
   address customers.address%type; 
   CURSOR customers_c is 
      SELECT id, name, address FROM customers; 
BEGIN 
   OPEN customers_c; 
   LOOP     --Compliant code (Unused labels removed)
   FETCH customers_c into id, name, address; 
      EXIT WHEN customers_c%notfound; 
      dbms_output.put_line(id || ' ' || name || ' ' || address); 
   END LOOP; 
   CLOSE customers_c; 
END; 
Visual Expert 2024
 VEPLSQLRULE107