I’m just beginning to learn stored functions in mysql. Can someone please tell me whats wrong with below?
Phpmyadmin says You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘return NAME;
END //’ at line 19
DELIMITER //
DROP FUNCTION IF EXISTS getName //
CREATE FUNCTION getName(type CHAR(10), id int) RETURNS CHAR(50) DETERMINISTIC
BEGIN
DECLARE NAME CHAR(50);
CASE type
WHEN 'offer' THEN
SELECT Type_Name INTO NAME FROM otypes WHERE Type_Id = id;
WHEN 'service' THEN
SELECT ServiceType_Name INTO NAME FROM stypes WHERE ServiceType_Id = id;
WHEN 'store' THEN
SELECT Store_Name INTO NAME FROM stores WHERE Store_Id = id;
END CASE
return NAME;
END //
Put a semicolon after
END CASE: