DECLARE v_result, v_word VARCHAR(2000) DEFAULT '';
FOR i IN 1..length(p_string) + 1 - length(replace(p_string, ' ', '')) -- word count
DO
SET v_word = ifnull(SUBSTRING_INDEX(SUBSTRING_INDEX(p_string, ' ', i), ' ', -1), '');
SET v_result = CONCAT(v_result, ' ', UPPER(SUBSTR(v_word, 1, 1)), LOWER(SUBSTR(v_word, 2)));
END FOR;
RETURN v_result;