Home

IF...ELSEIF constructs should end with ELSE clauses

Rule description

  • IF...ELSEIF constructs should end with ELSE clauses

 

Non-compliant Code Example

DECLARE flag BOOLEAN := TRUE;
BEGIN
  IF flag THEN                     
    DBMS_OUTPUT.PUT_LINE('flag is true!');
  ELSIF NOT flag THEN                   --Non compliant code (IF...ELSEIF clause without ELSE clause)
    DBMS_OUTPUT.PUT_LINE('flag is false!');
  END IF;
END;

Compliant Code Example

DECLARE flag BOOLEAN := TRUE;
BEGIN
  IF flag THEN                     
    DBMS_OUTPUT.PUT_LINE('flag is true!');
  ELSE THEN                     --Compliant code (IF...ELSEIF clause with ELSE clause)
    DBMS_OUTPUT.PUT_LINE('flag is false!');
  END IF;
END;
Visual Expert 2020
 VEPLSQLRULE145