需要Mysql存储函数帮助
我刚刚开始学习mysql中的存储函数。有人可以告诉我下面有什么问题吗?
Phpmyadmin 说您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 'return NAME; 附近使用的正确语法。 END //' 在第 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 //
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 //
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
END CASE
后添加分号:Put a semicolon after
END CASE
:您缺少
;
应该是
You missing a
;
should be