Home

Identical expressions should not be used on both sides of a binary operator

Description

    The Pl_Sql code rule "Identical expressions should not be used on both sides of a binary operator" states that when writing code, the same expression should not be used on both sides of a binary operator. This is because the expression on the left side of the operator will be evaluated first, and then the expression on the right side will be evaluated. If the same expression is used on both sides, the result of the evaluation will always be the same, and the code will not produce the desired result. This rule helps to ensure that code is written correctly and produces the desired results.

Key Benefits

  • Eliminates Confusion: Using identical expressions on both sides of a binary operator can lead to confusion and mistakes, as it is difficult to tell which side is being used for what purpose. By avoiding this, code is easier to read and understand.
  • Reduces Errors: By avoiding identical expressions on both sides of a binary operator, errors are reduced as it is easier to identify what each side is used for. This makes code more reliable and consistent.
  • Improves Performance: Using identical expressions on both sides of a binary operator can lead to unnecessary work, as the same expression may be evaluated multiple times. By avoiding this, performance is improved.

 

Non-compliant Code Example

SELECT
    NAME as nameCol,
    ADDRESS as addressCol,
    CREDIT_LIMIT as creditLimitCol,
	City
FROM
    CUSTOMERS
Where
	CREDIT_LIMIT > 1000 OR CREDIT_LIMIT > 1000 --Non compliant code (Identical expression on both the side of binary operator)

Compliant Code Example

SELECT
    NAME as nameCol,
    ADDRESS as addressCol,
    CREDIT_LIMIT as creditLimitCol,
	City
FROM
    CUSTOMERS
Where
	CREDIT_LIMIT > 1000 OR CREDIT_LIMIT < 2000 --Compliant code
Visual Expert 2024
 VEPLSQLRULE60