Home

Collapsible if statements should be merged

Rule description

  • Collapsible if statements should be merged

 

Non-compliant Code Example

BEGIN
 IF score > 35 THEN   -- Non compliant code (Multiple collapsible if statements)
     IF score > 40 THEN 
		IF score > 50 THEN 
			IF score > 60 THEN 
				IF score > 70 THEN 
					DBMS_OUTPUT.PUT('Grade A');
				END IF;
			END IF;
			DBMS_OUTPUT.PUT('Grade B');
		END IF;
	END IF;
	DBMS_OUTPUT.PUT('Grade C');
 END IF;
END;

Compliant Code Example

BEGIN
IF score > 70 THEN  
	DBMS_OUTPUT.PUT('Grade A');
ELSIF score > 50 AND score < 70 THEN  -- Compliant code 
	DBMS_OUTPUT.PUT('Grade B');
ELSIF score > 35 AND score < 50 THEN  -- Compliant code 
	DBMS_OUTPUT.PUT('Grade C');
ELSE 
	DBMS_OUTPUT.PUT('Grade D');
END IF;					
END;
  
Visual Expert 2020
 VEPLSQLRULE106