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.

Table 1. Order of precedence list
P Syntax Element A Description Example
15
CAST(var AS class)
N Type casting
CAST(var AS 
java.lang.Number)
15
var INSTANCEOF class
L Type checking
var INSTANCEOF 
java.lang.Boolean
14
UNITS
L Single-qualifier interval
(12) UNITS DAY
13
+ (unary)
R Unary plus
+324
13
- (unary)
R Unary minus
-324
12
**
L Exponentiation
x ** 5
12
MOD
L Modulus
x MOD 2
11
*
L Multiplication
x * y
11
/
L Division
x / y
10
+
L Addition
x + y
10
-
L Subtraction
x - y
9
||
L Concatenation
"Amount:" || amount
8
LIKE
R String comparison
mystring LIKE "A%"
8
MATCHES
R String comparison
mystring MATCHES "A*"
7
IN()
L List comparison
var IN('CA','NY')
6
<
L Less than
var < 100
6
<=
L Less then or equal to
var <= 100
6
>
L Greater than
var > 100
6
>=
L Greater than or equal to
var >= 100
6
==
L Equals
var == 100
6
<> or !=
L Not equal to
var <> 100
5
IS NULL
L Test for NULL
var IS NULL
5
IS NOT NULL
L Test for NOT NULL
var IS NOT NULL
4
NOT
L Logical inverse
NOT ( a = b )
3
AND
L Logical intersection
expr1 AND expr2
2
OR
L Logical union
expr1 OR expr2
1
ASCII(integer)
R ASCII Character
ASCII(32)
1
CLIPPED
R Delete trailing blanks
DISPLAY string CLIPPED
1
COLUMN integer
R Begin line mode display
PRINT COLUMN 32, "a"
1
(integer) SPACES
R Insert blank spaces
DISPLAY "a" (5) SPACES
1
SQLSTATE
R SQL State Code
IF SQLSTATE="IX000"
1
SQLERRMESSAGE
R SQL Error Message
DISPLAY SQLERRMESSAGE
1
USING
R Format character string
TODAY USING "yy/mm/dd"
1
:=
L Assignment
var:= "abc"

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).