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
-
MOD
returns the remainder ofExpression1
divided byExpression2
. -
If
Expression2
is0
, thenMOD
returnsExpression1
. -
If either
Expression1
orExpression2
isNULL
,MOD
returnsNULL
. -
MOD
is treated as a binary arithmetic operation, so the return type is determined according to the rules specified in the "Data Types" chapter. -
The
MOD
function 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) 11
3
2
2
11
-
3
-1
2
-11
3
1
-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
,n
FROM test WHERE MOD(m
,n
) = 0;