SQL REMAINDER() Function
SQL REMAINDER() Function return the remainder value of n1 divide by n2. Where n1 and n2 is natural value.
SQL REMAINDER() Function explicitly uses ROUND() function to finding remainder formula.
r = remainder
n = number
d = divisor
r = n - (d * (n / d))
WHERE (n / d) = (37 / 5) = 7
(d * 7) = 5 * 7 = 35
n - (35) = 37 - 35 = 2
Supported Oracle SQL Version
- Oracle 10g
- Oracle 11g
- Oracle 12c
- Oracle 18c
Syntax
REMAINDER(n1,n2)
Example
Considering following example 4 raised to a 2 return the 16.
SQL> SELECT REMAINDER(37,5) "REMAINDER" FROM DUAL;
REMAINDER
----------
2
SQL> SELECT REMAINDER(29,5) "REMAINDER" FROM DUAL;
REMAINDER
----------
-1
SQL> SELECT REMAINDER(28,5) "REMAINDER" FROM DUAL;
REMAINDER
----------
-2
SQL> SELECT REMAINDER(27,5) "REMAINDER" FROM DUAL;
REMAINDER
----------
2