Home

CASE should be used for sequences of simple tests

Rule description

  • CASE should be used for sequences of simple tests

 

Non-compliant Code Example

DECLARE flag BOOLEAN := TRUE;
BEGIN
  IF flag = FALSE THEN        --Non compliant code (Case when clause should be used for sequence of tests)             
    DBMS_OUTPUT.PUT_LINE('flag is false!');
  ELSIF flag = TRUE THEN      --Non compliant code (Case when clause should be used for sequence of tests)                     
    DBMS_OUTPUT.PUT_LINE('flag is true!');
  END IF;
END;

Compliant Code Example

DECLARE flag BOOLEAN := TRUE;
BEGIN

  CASE
    WHEN NOT flag THEN          --Compliant code
		DBMS_OUTPUT.PUT_LINE('flag is false!');
	WHEN flag THEN          --Compliant code
		DBMS_OUTPUT.PUT_LINE('flag is true!');
	
  END CASE;
END;
Visual Expert 2020
 VEPLSQLRULE181