All Products
Search
Document Center

Arithmetic operators

Last Updated: Dec 31, 2019

The following table lists all arithmetic operators.

Operator Operand Description
+ Unary or binary As a unary operator, it indicates a positive number. As a binary operator, it indicates an addition.
N/A Unary or binary As a unary operator, it indicates a negative number. As a binary operator, it indicates a subtraction.
* Binary Multiplication.
/ Binary Division.
DIV Binary Divides an integer and returns the quotient.
MOD or % Binary Divides an integer and returns the remainder.

Integer division follows these rules:

  • The quotient is rounded towards zero regardless of whether it is positive or negative.
  • The remainder has the same sign as the dividend.

Example:

  1. OceanBase (root@oceanbase)> SELECT (-7) DIV (3.6), (-7) MOD (3.6);
  2. +----------------+----------------+
  3. | (-7) DIV (3.6) | (-7) MOD (3.6) |
  4. +----------------+----------------+
  5. | -1 | -3.4 |
  6. +----------------+----------------+
  7. 1 row in set (0.01 sec)
  8. OceanBase (root@oceanbase)> SELECT (-7) DIV (-3.4), (-7) % (-3.4);
  9. +-----------------+---------------+
  10. | (-7) DIV (-3.4) | (-7) % (-3.4) |
  11. +-----------------+---------------+
  12. | 2 | -0.2 |
  13. +-----------------+---------------+
  14. 1 row in set (0.02 sec)