Name
MOD
Synopsis
The MOD function returns the remainder of one number when divided by a second number. The specification for the MOD function is:
FUNCTION MOD (dividend
NUMBER,divisor
NUMBER) RETURN NUMBER;
If the divisor
is zero, then the
dividend
is returned unchanged. Here are some
examples of MOD:
MOD (10, 5) --> 0 MOD (2, 1) --> 0 MOD (3,2) --> 1
You can use MOD to determine quickly if a number is odd or even:
FUNCTION is_odd (num_in IN NUMBER) RETURN BOOLEAN IS BEGIN RETURN MOD (num_in, 2) = 1; END; FUNCTION is_even (num_in IN NUMBER) RETURN BOOLEAN IS BEGIN RETURN MOD (num_in, 2) = 0; END;
Get Oracle PL/SQL Programming, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.