Order of precedence
The order of precedence defines in which order the elements of an expression are evaluated.
The following list describes the precedence order of expression elements in the meaning of
operators with operands such as
operand1+operand2
.
For example, the MOD
operator has a higher precedence as the *
operator. When computing an expression like ( 33 MOD 2 * 5 )
, the runtime system
first evaluates (33 MOD 2) = 1
and then evaluates (1 * 5) = 5
. The
order of evaluation can be changed this by using parentheses: ( 33 MOD ( 2 * 5 ) ) =
3
.
Some language elements such as compounds operators (+=
) that can only be used in
the LET
statement are not listed in the operators precedence table.
Language elements such as NVL()
or predefined variales such as SQLSTATE
are not part of this list:
These are similar to regular user functions or variables, and have the lowest order of precedence.
The function-like and variable-like language elements are respectively marked with the
[function] and [variable] indicators in there reference
topics.
P | Syntax Element | A | Description | Example |
---|---|---|---|---|
19 |
|
L | Single-qualifier interval |
|
18 |
|
L | Unary plus |
|
18 |
|
L | Unary minus |
|
17 |
|
L | Exponentiation |
|
16 |
|
L | Modulus |
|
16 |
|
L | Multiplication |
|
16 |
|
L | Division |
|
15 |
|
L | Addition |
|
15 |
|
L | Subtraction |
|
14 |
|
L | Concatenation |
|
13 |
|
L | String comparison |
|
13 |
|
L | String comparison |
|
12 |
|
L | List comparison |
|
11 |
|
L | Less than |
|
11 |
|
L | Less then or equal to |
|
11 |
|
L | Greater than |
|
11 |
|
L | Greater than or equal to |
|
11 |
|
L | Equals |
|
11 |
|
L | Not equal to |
|
10 |
|
R | ASCII Character |
|
10 |
|
R | Begin line mode display |
|
9 |
|
L | Insert blank spaces |
|
8 |
|
L | Delete trailing blanks |
|
8 |
|
L | Report wordwrapping |
|
8 |
|
L | Test for NULL |
|
7 |
|
L | Logical inverse |
|
6 |
|
L | Logical intersection |
|
5 |
|
L | Logical union |
|
4 |
|
L | Report aggregate condition |
|
3 |
|
L | Format character string |
|
2 |
|
L | Assignment |
|
1 |
|
L | Type checking |
|
- The
P
column defines the precedence, from highest to lowest. Note that some operators have the same precedence (i.e. are equivalent in evaluation order). - The
A
column defines the direction of associativity (L=left-associative, R=right-associative). Consider the expressionx % y % z
. If the operator%
has left associativity, it would be interpreted as(x % y) % z
. If the operator has right associativity, it would be interpreted asx % (y % z)
.