MOD
functionsupportedCore SQL functionsReturns the remainder of input expr1 divided by input expr2. Equivalent to the modulo arithmetic operator (for example, expr1 % expr2).
Syntax
MOD( <expr1> , <expr2> )
Parameters
| Name | Required | Description |
|---|---|---|
expr1 | required | A numeric expression. |
expr2 | required | A numeric expression. |
Returns
Returns either an integer or a fixed-point decimal number.
Usage notes
- Both expr1 and expr2 must be numeric expressions. They aren’t required to be integers.
- The returned value is the remainder from truncation-based division (rounding toward zero), not floor-based division (rounding down). Therefore, if expr1 is negative, the returned value is negative. This behavior is different from some programming languages (such as Python), but consistent with standard SQL. For more information, see the Modulo Wikipedia page.