Purpose
This function returns the remainder after dividing two numeric expressions. The sign of the result is the same as the sign of the dividend.
Notice
Both the REMAINDER (x,y) and MOD (x,y) functions use the formula result=x-y*(x/y). The difference lies in how x/y is calculated. In the REMAINDER (x,y) function, ROUND(x/y) is used, while in the MOD (x,y) function, FLOOR(x/y) is used.
Syntax
MOD (x,y)
Parameters
Parameter |
Description |
|---|---|
| x | The dividend, which is a numeric expression (NUMBER, FLOAT, BINARY_FLOAT, or BINARY_DOUBLE). |
| y | The divisor, which is a numeric expression (NUMBER, FLOAT, BINARY_FLOAT, or BINARY_DOUBLE). |
Return type
The return type is the data type of the numeric expression with the higher precedence.
Examples
Return the remainder 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
