Oracle PL/SQL - PL SQL Operator Operator Precedence

Introduction

The following table shows the precedence of operators in PL/SQL organized from highest to lowest.

Operator
Description
**
Exponentiation
+, -
Identity, negation (unary operation)
*, /
Multiplication, division
+, -, ||
Addition, subtraction, concatenation
=, <, >, <=, >=, <>, !=, ~=
IS NULL, LIKE, BETWEEN, IN
Comparison

NOT
Logical negation
AND
Conjunction
OR
Inclusion

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.

Operator Operation
** exponentiation
+, - identity, negation
*, /multiplication, division
+, -, ||addition, subtraction, concatenation
=, <, >, <=, >=, <>, !=, ~=, ^=, IS NULL, LIKE, BETWEEN, IN comparison
NOT negation
AND conjunction
OR inclusion

To control the order of evaluation, enclose operations in parentheses.

When parentheses are nested, the most deeply nested operations are executed first.

Demo

SQL>
SQL> DECLARE-- from  w  w w .  j a  v a  2s. c  o m
  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>

Related Topics

Quiz