Oracle Number Function - Oracle/PLSQL REMAINDER Function






REMAINDER(n1, n2) identifies the multiple of n2 that is nearest to n1, and returns the difference between those two values.

This Oracle tutorial explains how to use the Oracle/PLSQL REMAINDER function.

The Oracle/PLSQL REMAINDER function returns the remainder of m divided by n.

Syntax

The syntax for the Oracle/PLSQL REMAINDER function is:

REMAINDER( m, n )

The REMAINDER is calculated as:

m - (n * X) where X is the integer nearest m / n

Example


SQL> SELECT REMAINDER(9,3), REMAINDER(10,3), REMAINDER(11,3) FROM   DUAL;

REMAINDER(9,3) REMAINDER(10,3) REMAINDER(11,3)
-------------- --------------- ---------------
             0               1              -1

SQL>

REMAINDER(11,3) doesn't return a 2. Instead, it returns a -1, because the nearest integer that's divisible by 3 is 12, which is closer to the 11 than the 9. REMAINDER identifies the closest multiple of n2. If the multiple is higher, REMAINDER returns a negative number to indicate that the closest multiple of n2 is higher than n1.