What is MOD() in SQL?
The MOD() function returns the remainder of a dividend divided by a divisor. Figure 1 shows the mathematical representation of the MOD() function.
Syntax
MOD(dividend, divisor)
Parameter
The MOD() function requires two parameters:
- A dividend can be any number.
- A divisor can be any number except zero.
NOTE: A divisor should not be zero.
Return value
MOD() returns the remainder of a dividend divided by a divisor that is sent as a parameter.
NOTE: If a divisor is zero, then
MOD()returnsNULL.
Example
/*example showing how to use MOD(X)*/-- positive numberselect MOD(4,3);-- negative numberselect MOD(-6,3);-- fractional numberselect MOD(4.6,2.1);-- zero divisorselect MOD(4,0)