The following table shows the precedence of operators in PL/SQL organized from highest to lowest.
|+, -|| Identity, negation (unary operation)|
|*, /|| Multiplication, division|
|+, -, |||| Addition, subtraction, concatenation|
|=, <, >, <=, >=, <>, !=, ~=|
IS NULL, LIKE, BETWEEN, IN
|NOT|| Logical negation|
Operations with higher precedence are executed first.
Operators with the same precedence are applied in their text order.
You can insert extra parentheses to logically separate parts of a statement or condition.
The operations in an expression are evaluated in order of operator precedence.
The following Table shows operator precedence from highest to lowest.
Operators with equal precedence are evaluated in no particular order.
|+, -||identity, negation|
|*, /||multiplication, division|
|+, -, ||||addition, subtraction, concatenation|
|=, <, >, <=, >=, <>, !=, ~=, ^=, IS NULL, LIKE, BETWEEN, IN||comparison|
To control the order of evaluation, enclose operations in parentheses.
When parentheses are nested, the most deeply nested operations are executed first.
SQL> SQL> DECLARE-- w w w . ja v a 2 s .com 2 a INTEGER := 1+2**2; 3 b INTEGER := (1+2)**2; 4 BEGIN 5 DBMS_OUTPUT.PUT_LINE('a = ' || TO_CHAR(a)); 6 DBMS_OUTPUT.PUT_LINE('b = ' || TO_CHAR(b)); 7 END; 8 / a = 5 b = 9 PL/SQL procedure successfully completed. SQL>