Tuesday, April 8, 2014

PL/SQL - Operator Precedence




In SQL or PL/SQL we use several operators. Some are mathematical, logical and comparison operators. Oracle follow a order of precedence when execute an expression that contains more than one operators. If operators with same precedence are occurred then it does not follow any order. Otherwise Oracle maintain the following order of precedence of operators.


Order |------------| Operator |------------| Operation
1 |------------| ** |------------| exponentiation
2 |------------| +, |------------| identity, negation
3 |------------| *, / |------------| multiplication, division
4 |------------| +, -, || |------------| addition, subtraction, concatenation
5 |------------| =, <, >, <=, >=, |------------| comparison
<>, !=, ~=, ^=, IS NULL, LIKE,
BETWEEN, IN
6 |------------| NOT |------------| logical negation
7 |------------| AND |------------| conjunction
8 |------------| OR |------------| inclusion


For example, when NOT, AND and OR operators are used in the same statement NOT is evaluated first, then AND and finally OR.


No comments:

Post a Comment