Home

All branches in a conditional structure should not have exactly the same implementation

Description

    The rule "All branches in a conditional structure should not have exactly the same implementation" states that when writing a PL/SQL code that contains a conditional structure (such as an IF statement), each branch of the conditional structure should have a different implementation. This means that the code should not be written in such a way that all of the branches have the same implementation, as this would be redundant and could lead to inefficient code. This rule helps to ensure that the code is written in an efficient and effective manner.

Key Benefits

  • Flexibility: All branches in a conditional structure can have different implementation rules, allowing for greater flexibility in the code.
  • Efficiency: Different implementation rules can lead to more efficient code, as the code can be tailored to the specific needs of the program.
  • Robustness: Different implementation rules can help ensure that the code is robust and can handle different scenarios without breaking.

 

Non-compliant Code Example

BEGIN

   IF salary <= 20000 THEN
      EmpLevel := 'Average Salary';

   ELSIF salary > 20000 and salary <= 60000 THEN
      EmpLevel := 'Average Salary'; --Non compliant code (IF Else condition is having same implementation)

   ELSIF salary > 6000 and salary <= 110000 THEN
      EmpLevel := 'Average Salary';

   ELSE
      EmpLevel := 'Average Salary';

   END IF;

END;

Compliant Code Example

BEGIN

   IF salary <= 20000 THEN
      EmpLevel := 'Low Salary';

   ELSIF salary > 20000 and salary <= 60000 THEN
      EmpLevel := 'Average Salary'; --Compliant code (All IF Else condition is having different implementation)

   ELSIF salary > 6000 and salary <= 110000 THEN
      EmpLevel := 'Moderate Salary';

   ELSE
      EmpLevel := 'High Salary';

   END IF;

END;
Visual Expert 2024
 VEPLSQLRULE50