Oracle PL/SQL - Expression Operator Precedence with Nested Parentheses

Introduction

In the following code, the operations (1+2) and (3+4) are evaluated first, producing the values 3 and 7, respectively.

Next, the operation 3*7 is evaluated, producing the result 21.

Finally, the operation 21/7 is evaluated, producing the final value 3.

Demo

SQL>
SQL> DECLARE-- from w w  w .jav  a 2s.c  o  m
  2    a INTEGER :=  ((1+2)*(3+4))/7;
  3  BEGIN
  4    DBMS_OUTPUT.PUT_LINE('a = ' || TO_CHAR(a));
  5  END;
  6  /
a = 3

PL/SQL procedure successfully completed.

SQL>

Related Topic