# 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`.

Table 1. Order of precedence list
P Syntax Element A Description Example
14
``CAST(var AS class)``
N Type casting
``````CAST(var AS
java.lang.Number)``````
14
``var INSTANCEOF class``
L Type checking
``````var INSTANCEOF
java.lang.Boolean``````
13
``UNITS``
L Single-qualifier interval
``(12) UNITS DAY``
12
``+ (unary)``
R Unary plus
``+324``
12
``- (unary)``
R Unary minus
``-324``
11
``**``
L Exponentiation
``x ** 5``
11
``MOD``
L Modulus
``x MOD 2``
10
``*``
L Multiplication
``x * y``
10
``/``
L Division
``x / y``
9
``+``
``x + y``
9
``-``
L Subtraction
``x - y``
8
``||``
L Concatenation
``"Amount:" || amount``
7
``LIKE``
R String comparison
``mystring LIKE "A%"``
7
``MATCHES``
R String comparison
``mystring MATCHES "A*"``
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).