The MOD function in Oracle SQL / PLSQL is used to get the remainder of ‘n’ divided by ‘m’.
Syntax for the MOD function in Oracle SQL / PLSQL is:
SELECT MOD(n,m)
FROM table_name;
- MOD is calculated as n – m * floor(n/m)
- MOD function uses floor in the calculation whereas remainder function uses round function in its calculation.
- MOD function will return ‘n’ if ‘m’ is ‘0’.
Example 1:
SELECT MOD(5,2) FROM DUAL;
Will return “1” because 1 will be remainder if 5 is divided by 2
Example 2:
SELECT MOD(6,2) FROM DUAL;
Will return “0” because there is no remainder if 6 is divided by 2
Example 3:
SELECT MOD(-5,2) FROM DUAL;
Will return “-1” because -1 will be remainder if -5 is divided by 2
Example 4:
SELECT MOD(5,0) FROM DUAL;
Will return “5”
Example 5:
SELECT MOD(5.5,2) FROM DUAL;
Will return “1.5” because 1.5 will be remainder if 5.5 is divided by 2