Friday, January 11, 2013

Mod Function


In Oracle/PLSQL, the mod function returns the remainder of m divided by n.

Syntax

The syntax for the mod function is:
mod( m, n )
The mod is calculated as:
m - n * floor(m/n)

Note

The mod function uses the floor function in its formula, whereas the remainder function uses the round function in its formula.
The mod function returns m if n is 0.

Applies To

  • Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i

For Example

mod(15, 4)would return 3
mod(15, 0)would return 15
mod(11.6, 2)would return 1.6
mod(11.6, 2.1)would return 1.1
mod(-15, 4)would return -3
mod(-15, 0)would return -15