This is for my database class. My Professor wants us to make a stored function. Here is the question specifically.
Please write a stored function named fHW2_4_XXXX (...) based on the Guest table. Your program should take one argument city and it should meet the following 3 test cases.
Full Question ~ Given by my Professor ~ Click here to see it!
I realize there are similar questions, but the ones I've seen have not helped. I'm trying to create a stored function in MySQL, and it's giving me the error: "Not allowed to return a result set from a function."
DELIMITER //
CREATE FUNCTION fHW2_4_xxxx(city_name VARCHAR(25))
RETURNS VARCHAR(255)
BEGIN
DECLARE names VARCHAR(255);
IF (city_name = '' OR city_name IS NULL) THEN
SELECT 'Please input a valid city.' AS message;
ELSE
SELECT GROUP_CONCAT(guestname SEPARATOR ',') INTO names FROM dreamhome.Guest WHERE guestaddress LIKE CONCAT('%', city_name, '%');
RETURN names;
END IF;
END //
DELIMITER ;
The goal is to select all guestname(s) from dreamhome.Guest whose address contains the given (input) city name, but it has to return the values as "John Kay, Mike Ritchie". This is for my Database class. I understand it has something to do with my SELECT statements, but I see no other reliable way to do it.