OceanBase AI Database supports common arithmetic operators.
Overview of Arithmetic Operators
The following table describes the arithmetic operators supported by the current version of OceanBase AI Database.
operator |
Operand type |
Meaning |
|---|---|---|
+ |
Univariate/Bivariate | A unary operator indicates a positive number, and a binary operator indicates addition. |
- |
Univariate/Bivariate | A unary prefix indicates a negative number, and a binary prefix indicates subtraction. |
* |
binary | Multiplication. |
/ |
binary | Regular division. |
DIV |
binary | Integer division, returns the quotient. |
MOD or % |
binary | Integer division, returning the remainder. N % M or N MOD M denotes the remainder of dividing N by M. |
Description
Arithmetic rules
The following rules apply to integer division:
The quotient, regardless of its sign, is uniformly rounded down to 0.
The sign of the remainder is the same as the dividend.
An example is as follows:
obclient> SELECT (-7) DIV (3.6), (-7) MOD (3.6);
+----------------+----------------+
| (-7) DIV (3.6) | (-7) MOD (3.6) |
+----------------+----------------+
| -1 | -3.4 |
+----------------+----------------+
1 row in set
obclient> SELECT (-7) DIV (-3.4), (-7) % (-3.4);
+-----------------+---------------+
| (-7) DIV (-3.4) | (-7) % (-3.4) |
+-----------------+---------------+
| 2 | -0.2 |
+-----------------+---------------+
1 row in set
Operation result
The result of an arithmetic operation is determined by the following rules:
For
-,+, and*, if both operands are integers, the result is calculated withBIGINT(64-bit) precision.If both operands are integers and one of them is unsigned, the result is an unsigned integer. For subtraction, if the
NOUnsigned_SUBTRACTIONSQL mode is enabled, the result is signed even if either operand is unsigned.If the operands of
+,-,/,*, and%are real numbers or string values, the result has the precision of the operand with the highest precision.When using the
/operator for division, if both operands are exact values, the number of decimal places in the result is the number of decimal places in the first operand plus the value of thediv_precision_incrementsystem variable (which defaults to 4). For example, the expression 5.15/0.013 results in six decimal places (396.153846).