All Products
Search
Document Center

Arithmetic operators

Last Updated: Jun 18, 2021

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.

-

Unary or binary

As a unary operator, it indicates a negative number. As a binary operator, it indicates a subtraction.

*

Binary

The multiplication operator.

/

Binary

The division operator.

DIV

Binary

Divides an integer and returns the quotient.

MOD or %

Binary

Divides an integer and returns the remainder.

Integer division complies with the following rules:

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

Examples

OceanBase (root@oceanbase)> SELECT (-7) DIV (3.6), (-7) MOD (3.6);
+----------------+----------------+
| (-7) DIV (3.6) | (-7) MOD (3.6) |
+----------------+----------------+
|             -1 |           -3.4 |
+----------------+----------------+
1 row in set (0.01 sec)

OceanBase (root@oceanbase)> SELECT (-7) DIV (-3.4), (-7) % (-3.4);
+-----------------+---------------+
| (-7) DIV (-3.4) | (-7) % (-3.4) |
+-----------------+---------------+
|               2 |          -0.2 |
+-----------------+---------------+
1 row in set (0.02 sec)