DROP FUNCTION IF EXISTS getIncomeLevel;
DELIMITER //
CREATE FUNCTION getIncomeLevel ( monthly_value INT )
RETURNS varchar(20)
BEGIN
DECLARE income_level varchar(20);
IF monthly_value <= 4000 THEN
SET income_level = 'Low Income';
ELSEIF monthly_value > 4000 AND monthly_value <= 7000 THEN
SET income_level = 'Avg Income';
ELSE
SET income_level = 'High Income';
END IF;
INSERT INTO log (description)
VALUES ('getIncomeLevel function was called');
RETURN income_level;
END; //
DELIMITER ;
After creating the function we can call it:
SELECT getIncomeLevel(450)