Skip to content

G-1080: Avoid using the same expression on both sides of a relational comparison operator or a logical operator.

Blocker

Maintainability, Efficiency, Testability

Reason

Using the same value on either side of a binary operator is almost always a mistake. In the case of logical operators, it is either a copy/paste error and therefore a bug, or it is simply wasted code and should be simplified.

This rule ignores operators +, * and ||, and expressions: 1=1, 1<>1, 1!=1, 1~=1 and 1^=1.

Example (bad)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
declare
   co_max_salary constant emp.salary%type := 3000;
begin
   select emp.first_name
         ,emp.last_name
         ,emp.salary
         ,emp.hire_date
     from employees emp
    where emp.salary > co_max_salary
       or emp.salary > co_max_salary
    order by emp.last_name,emp.first_name;
end;
/

Example (good)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
declare
   co_max_salary constant emp.salary%type := 3000;
begin
   select emp.first_name
         ,emp.last_name
         ,emp.salary
         ,emp.hire_date
     from employees emp
    where emp.salary > co_max_salary
    order by emp.last_name,emp.first_name;
end;
/