Home

Nested loops should be labeled

Rule description

  • Nested loops should be labeled

 

Non-compliant Code Example

BEGIN
  FOR order_table IN (SELECT * FROM orders) LOOP
    FOR order_items_table IN (SELECT * FROM order_items) LOOP       --Non compliant code (Nested loop is not labeled)
      DBMS_OUTPUT.PUT_LINE('Order Id: ' || order_table.id || ', Order Amount: ' || order_table.amount || ', Order Items: ' || order_items_table.Quantity);
    END LOOP;
  END LOOP;
END;

Compliant Code Example

BEGIN
	<<outer_for_loop>>
	FOR order_table IN (SELECT * FROM orders) LOOP
		<<inner_for_loop>> 
		FOR order_items_table IN (SELECT * FROM order_items) LOOP       --Compliant code (Nested loop is labeled)
			  DBMS_OUTPUT.PUT_LINE('Order Id: ' || order_table.id || ', Order Amount: ' || order_table.amount || ', Order Items: ' || order_items_table.Quantity);
		END LOOP inner_for_loop;
  END LOOP outer_for_loop;
END;
Visual Expert 2020
 VEPLSQLRULE157