Home

GOTO statements should not be used

Rule description

  • GOTO statements should not be used

 

Non-compliant Code Example

DECLARE
  first_name  VARCHAR2(25);
  customer_id     NUMBER(6) := 120;
BEGIN
 
  
  BEGIN
    DBMS_OUTPUT.PUT_LINE (first_name);
    customer_id := customer_id + 1;
 
    IF customer_id < 200 THEN
      GOTO get_customer_name;  -- Non compliant code (GOTO statement should not be used)
    END IF;

    <<get_customer_name>>
      SELECT FIRSTNAME INTO first_name
      FROM CUSTOMERS
      WHERE Id = customer_id;
  END;
END;

Compliant Code Example

DECLARE
    first_name  VARCHAR2(25);
    customer_id NUMBER(6) := 120;
BEGIN
    BEGIN
        DBMS_OUTPUT.PUT_LINE(first_name);
        customer_id:= customer_id + 1;

        IF customer_id< 200 THEN            -- Compliant code (GOTO statement is not used)
            SELECT FIRSTNAME INTO first_name
            FROM CUSTOMERS
            WHERE Id = customer_id;
        END IF;
    END;
END;
Visual Expert 2020
 VEPLSQLRULE66