Home

Related IF / ELSIF statements and WHEN clauses in a CASE should not have the same condition

Rule description

  • Related IF / ELSIF statements and WHEN clauses in a CASE should not have the same condition

 

Non-compliant Code Example

DECLARE flag BOOLEAN := TRUE;
BEGIN

  CASE
    WHEN flag THEN
		DBMS_OUTPUT.PUT_LINE('flag is false!');
	WHEN flag THEN                          --Non compliant code (When clause in the Case having the same condition)
		DBMS_OUTPUT.PUT_LINE('flag is true!');
	
  END CASE;
END;

Compliant Code Example

DECLARE flag BOOLEAN := TRUE;
BEGIN

  CASE
    WHEN NOT flag THEN
		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
 VEPLSQLRULE59