Home

IF statement conditions should not evaluate unconditionally to TRUE or to FALSE

Description

    The IF statement condition should not evaluate unconditionally to TRUE or FALSE rule states that when writing an IF statement, the condition should not be written in a way that it will always evaluate to either TRUE or FALSE. This means that the condition should be written in a way that it can evaluate to either TRUE or FALSE depending on the data that is being evaluated. This is important in order to ensure that the IF statement will be able to evaluate the data accurately and provide the correct output.

Key Benefits

  • Prevent Unwanted Results: It helps to prevent unwanted results.
  • Ensure Accuracy: It ensures accuracy in the code.
  • Maintain Consistency: It helps to maintain consistency in the code.
  • Improve Performance: It helps to improve the performance of the code.

 

Non-compliant Code Example

BEGIN
IF TRUE THEN                --Non compliant code
	DBMS_OUTPUT.PUT('Success :)');
ELSIF FALSE THEN            --Non compliant code
	DBMS_OUTPUT.PUT('Failed !!');
END IF;					
END;

Compliant Code Example

BEGIN
IF flag THEN                --Compliant code
	DBMS_OUTPUT.PUT('Success :)');
ELSIF NOT flag THEN            --Compliant code
	DBMS_OUTPUT.PUT('Failed !!');
END IF;					
END;
Visual Expert 2024
 VEPLSQLRULE64