Purpose
MOD() returns the remainder of a numeric expression divided by another. The return value has the same sign as the dividend.
Notice
Both REMAINDER(x, y) and MOD(x, y) calculate the remainder by using the following formula: result = x - y * (x/y). The difference lies in the calculation of x/y. REMAINDER(x,y) uses ROUND(x/y), whereas MOD(x,y) uses FLOOR(x/y).
Syntax
MOD(x,y)
Parameters
| Parameter | Description |
|---|---|
| x | The dividend. It can be of any numeric data type, such as NUMBER, FLOAT, BINARY_FLOAT, or BINARY_DOUBLE. |
| y | The divisor. It can be of any numeric data type, such as NUMBER, FLOAT, BINARY_FLOAT, or BINARY_DOUBLE. |
Return type
The return type is the same as the data type of the parameter with the higher numeric precedence.
Examples
The following example returns the reminders of 11 divided by 4, 12 divided by 4, and -11 divided by 4.
obclient> SELECT MOD(11,4),MOD(12,4),MOD(-11,4) FROM DUAL;
+-----------+-----------+------------+
| MOD(11,4) | MOD(12,4) | MOD(-11,4) |
+-----------+-----------+------------+
| 3 | 0 | -3 |
+-----------+-----------+------------+
1 row in set