DELIMITER $$
DROP FUNCTION IF EXISTS dbname.getCompany$$
CREATE FUNCTION dbname.getCompany($p_cid VARCHAR(20)) RETURNS varchar(20) CHARSET utf8
BEGIN
DECLARE return_value VARCHAR(20);
SET return_value = null;
SELECT u.mf_code INTO return_value
FROM users u
WHERE u.cid = p_cid;
RETURN return_value;
END $$
DELIMITER ;