MOD
Returns the remainder of an INTEGER expression divided by a second INTEGER expression.
SQL syntax
MOD(Expression1, Expression2)
Parameters
MOD has the following parameters:
| Parameter | Description |
|---|---|
|
|
An |
|
|
An |
Description
-
MODreturns the remainder ofExpression1divided byExpression2. -
If
Expression2is0, thenMODreturnsExpression1. -
If either
Expression1orExpression2isNULL,MODreturnsNULL. -
MODis treated as a binary arithmetic operation, so the return type is determined according to the rules specified in the "Data Types" chapter. -
The
MODfunction behaves differently from the classic mathematical modulus function when one of the operands is negative. The following table illustrates this difference:M N Classic Modulus MOD(M,N) 1132211-
3-12-1131-2-11-3-2-2
The following example tests whether the value of the expression m is divisible by the value of expression n.
SELECTm,nFROM test WHERE MOD(m,n) = 0;