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.

SQL> SQL> DECLARE-- w w w . j a v a 2 s . co m 2 aINTEGER:= 1+2**2; 3 bINTEGER:= (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>

- What is the output: Division operator precedence?
- What is the output: Parentheses vs operator precedence?
- What is the output: with or without Parentheses?