存储过程语法错误

发布于 2024-09-09 08:38:56 字数 523 浏览 2 评论 0原文

我是存储过程公认的新手。以下是生成语法错误。

“您的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情仇皆在手 2024-09-16 08:38:56

看起来您需要在定义过程时使用 DELIMITER 命令将语句分隔符从 ; 更改为其他内容。这使得过程主体中使用的 ; 分隔符能够传递到服务器,而不是由 MySQL 本身解释。

因此,您可能想尝试以下操作:

DELIMITER $

CREATE PROCEDURE get_user_association_list (IN uid INT)
BEGIN

-- // Your stored procedure body, using semicolon delimiters

END $

DELIMITER ;

进一步阅读:

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:

DELIMITER $

CREATE PROCEDURE get_user_association_list (IN uid INT)
BEGIN

-- // Your stored procedure body, using semicolon delimiters

END $

DELIMITER ;

Further reading:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文