Operator precedence determines the order in which OceanBase Database evaluates different operators in the same expression.
When an expression contains multiple operators, OceanBase Database evaluates the operators with higher precedence before those with lower precedence. If the operators are of equal precedence, they are evaluated left to right in the expression.
The following table lists operators in descending order of precedence. Operators listed in the same row have the same precedence.
| Operator | Description |
|---|---|
| + and - (when they serve as unary operators), PRIOR, and CONNECT_BY_ROOT | Positive sign, negative sign, and location in hierarchy |
| * and / | Multiplication and division |
| + and - (when they serve as binary operators), and || | Addition, subtraction, and concatenation |
| Condition expressions are evaluated after OceanBase Database evaluates the operators. | For more information, see the Conditions. |
You can use parentheses in an expression to override operator precedence. OceanBase Database evaluates expressions inside parentheses before those outside.
SQL also supports set operators (UNION, UNION ALL, INTERSECT and MINUS). Set operators combine sets of rows returned by queries, rather than individual data items. All set operators have the same precedence.
In the following example, multiplication has a higher precedence than addition, so OceanBase Database first multiplies 2 by 3 and then adds the result to 1.
1+2*3