Functions: Sample Functions

Description: Functions to determine if a number is odd or even.

--Function to determine if a number is even:
 
CREATE OR REPLACE FUNCTION is_even(num_in NUMBER) RETURN BOOLEAN IS
BEGIN
  IF MOD(num_in, 2) = 0 THEN
    RETURN TRUE;
  END IF;
EXCEPTION
  WHEN OTHERS THEN
    RETURN FALSE;
END is_even;
/
 
 
 
 
-- Function to determine if a number is odd:
 
CREATE OR REPLACE FUNCTION is_odd(num_in NUMBER) RETURN BOOLEAN IS
BEGIN
  RETURN MOD(num_in, 2) = 1;
EXCEPTION
  WHEN OTHERS THEN
    RETURN FALSE;
END is_odd;
/

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.