REMAINDER

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


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.

Home »
Oracle »
Numeric Functions » 

Related: