Operator precedence determines the order of operations in an expression in OceanBase Database.
When evaluating an expression that contains multiple operators, OceanBase Database evaluates the operators with higher precedence first, and then evaluates the operators with lower precedence. When operators have the same precedence, they are evaluated from left to right in the expression.
The following table lists the operators from highest to lowest precedence. Operators in the same row have the same precedence.
| Operator | Operation |
|---|---|
| +, - (as unary operators), PRIOR, CONNECT_BY_ROOT | Positive sign, negative sign, and position in a hierarchy. |
| * and / | Multiplication and division. |
| +, - (as binary operators), and || | Addition, subtraction, and concatenation. |
| Conditional expressions are evaluated after the operators in the database are evaluated | For more information, see SQL conditions. |
You can also use parentheses in an expression to override the default precedence of operators. OceanBase Database evaluates the expressions in parentheses first, and then evaluates the expressions outside the parentheses.
SQL also supports set operators (UNION, UNION ALL, INTERSECT, and MINUS). Set operators combine the result sets of queries, not individual data items. All set operators have the same precedence.
In the following example, the database multiplies 2 by 3 first because multiplication has higher precedence than addition, and then adds the result to 1.
1+2*3
