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;

IF counter > 0 THEN
		cust_order := 1;
		message := 'Number is positive';
	ELSIF counter > 0 THEN            --Non compliant code (When clause in the Case having the same condition)
		cust_order := 2;
		message := 'Number is positive';
	ELSE
		cust_order := 0;
		message := 'Number is negative';
	END IF;

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