Skip to content

MOD Function

Returns the remainder of the numeric value expr1 divided by the numeric value expr2.

Syntax

sql
MOD(expr1, expr2)

Arguments

expr1 and expr2: Values of numeric data type.

If the value is not numeric, an attempt is made to convert the value to a numeric type. If conversion is not possible, an error is returned.

Return Values

The return value is of the DECIMAL data type.

Usage Notes

  • Both arguments must be numeric expressions.
  • If expr2 = 0, expr1 is returned.

Example 1

sql
SELECT mod(3, 2), mod(4.5, 1.2), mod(9, 3), mod(9, 0), mod(9, NULL);
+-----------+---------------+-----------+-----------+--------------+
| MOD(3, 2) | MOD(4.5, 1.2) | MOD(9, 3) | MOD(9, 0) | MOD(9, NULL) |
+-----------+---------------+-----------+-----------+--------------+
|         1 |           0.9 |         0 |         9 |         NULL |
+-----------+---------------+-----------+-----------+--------------+

Example 2

sql
SELECT mod(2, 3), mod(1.2, 4), mod('3', '9'), mod(-3, 9);
+-----------+-------------+-----------+------------+
| MOD(2, 3) | MOD(1.2, 4) | MOD(3, 9) | MOD(-3, 9) |
|-----------+-------------+-----------+------------+
|         2 |         1.2 |         3 |         -3 |
+-----------+-------------+-----------+------------+