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.
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.
P | Syntax Element | A | Description | Example |
---|---|---|---|---|
15 |
|
N | Type casting |
|
15 |
|
L | Type checking |
|
14 |
|
L | Single-qualifier interval |
|
13 |
|
R | Unary plus |
|
13 |
|
R | Unary minus |
|
12 |
|
L | Exponentiation |
|
12 |
|
L | Modulus |
|
11 |
|
L | Multiplication |
|
11 |
|
L | Division |
|
10 |
|
L | Addition |
|
10 |
|
L | Subtraction |
|
9 |
|
L | Concatenation |
|
8 |
|
R | String comparison |
|
8 |
|
R | String comparison |
|
7 |
|
L | List comparison |
|
6 |
|
L | Less than |
|
6 |
|
L | Less then or equal to |
|
6 |
|
L | Greater than |
|
6 |
|
L | Greater than or equal to |
|
6 |
|
L | Equals |
|
6 |
|
L | Not equal to |
|
5 |
|
L | Test for NULL |
|
5 |
|
L | Test for NOT NULL |
|
4 |
|
L | Logical inverse |
|
3 |
|
L | Logical intersection |
|
2 |
|
L | Logical union |
|
1 |
|
R | ASCII Character |
|
1 |
|
R | Delete trailing blanks |
|
1 |
|
R | Begin line mode display |
|
1 |
|
R | Insert blank spaces |
|
1 |
|
R | SQL State Code |
|
1 |
|
R | SQL Error Message |
|
1 |
|
R | Format character string |
|
1 |
|
L | Assignment |
|
In this table, the P
column defines the precedence, from highest (14) to lowest
(1). Note that some operators have the same precedence (i.e. are equivalent in evaluation order).
The A
column defines the direction of association (L=Left, R=Right, N=None).