存储过程语法错误
我是存储过程公认的新手。以下是生成语法错误。
“您的 SQL 语法有错误;请检查与您的 MySQL 服务器版本相对应的手册,以了解在第 3 行 '' 附近使用的正确语法”
CREATE PROCEDURE get_user_association_list (IN uid INT)
BEGIN
DECLARE rolelist VARCHAR(255);
DECLARE role_id INT;
DECLARE cur1 CURSOR FOR SELECT assoc_type_id FROM cause_users_assoc WHERE user_id = uid;
OPEN cur1;
REPEAT
FETCH cur1 INTO role_id;
SET rolelist = CONCAT(rolelist, role_id);
SET rolelist = CONCAT(rolelist, ',');
UNTIL done END REPEAT;
CLOSE cur1;
RETURN rolelist;
END;
请帮忙。
I'm an admitted newbie with stored procedures. The following is generating a syntax error.
"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 '' at line 3"
CREATE PROCEDURE get_user_association_list (IN uid INT)
BEGIN
DECLARE rolelist VARCHAR(255);
DECLARE role_id INT;
DECLARE cur1 CURSOR FOR SELECT assoc_type_id FROM cause_users_assoc WHERE user_id = uid;
OPEN cur1;
REPEAT
FETCH cur1 INTO role_id;
SET rolelist = CONCAT(rolelist, role_id);
SET rolelist = CONCAT(rolelist, ',');
UNTIL done END REPEAT;
CLOSE cur1;
RETURN rolelist;
END;
Help please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您需要在定义过程时使用
DELIMITER
命令将语句分隔符从;
更改为其他内容。这使得过程主体中使用的;
分隔符能够传递到服务器,而不是由 MySQL 本身解释。因此,您可能想尝试以下操作:
进一步阅读:
It looks like you need to use the
DELIMITER
command to change the statement delimiter from;
to something else while the procedure is being defined. This enables the;
delimiter used in the procedure body to be passed through to the server rather than being interpreted by MySQL itself.Therefore you may want to try the following:
Further reading: