skip to main content
Operators : Operator precedence
 

Operator precedence

When a complex expression has multiple operators, operator precedence determines the sequence in which the operations are performed. An operator on higher levels is evaluated before an operator on a lower level.
Operators have the following precedence levels:
+ (Positive), - (Negative), ~ (Bitwise NOT)
* (Multiply), / (Division),% (Modulo)
+ (Add), (+ Concatenate), - (Subtract)
=, >, <, >=, <=, <>, !=, !>, !< (Comparison operators)
^ (Bitwise Exclusive OR), & (Bitwise AND), | (Bitwise OR)
NOT
AND
ALL, ANY, BETWEEN, IN, LIKE, OR, SOME
= (Assignment)
When two operators in an expression have the same operator precedence level, they are evaluated left to right based on their position in the expression. Use parentheses to override the defined precedence of the operators in an expression. Everything within the parentheses is evaluated first to yield a single value before that value can be used by any operator outside of the parentheses.

Example 

SELECT * FROM emp WHERE (deptno = 1 OR deptno = 2) AND sal > 1000;
This query returns emp records whose deptno is 1 or 2 and sal is greater than 1000.
SELECT * FROM emp WHERE deptno = 1 or deptno = 2 AND sal > 1000;
The preceding search condition is equivalent to deptno = 1 OR (deptno = 2 AND sal > 1000). The query returns emp records where deptno is 1 or where deptno is 2 and sal is greater than 1000.