gpt4 book ai didi

mysql - 在 MySQL 中创建存储过程

转载 作者:行者123 更新时间:2023-11-29 05:19:18 25 4
gpt4 key购买 nike

我有以下用于在 MySQL 5.0.10 中创建存储过程的语法

delimiter //
CREATE PROCEDURE getTweets (var1 varchar(100))
LANGUAGE SQL
SQL SECURITY DEFINER
COMMENT 'A procedure to return 20 least scored tweets based on the temp sessionid of the user'
BEGIN
SELECT count(ts.tweetid) as "count",t.id as "tweetid", t.tweettext as "tweet"
FROM tweets t
LEFT JOIN tweetscores ts ON t.id = ts.tweetid
where t.id not in (select distinct(tweetid) from tweetscores where temp_sessionid=var1)
group by t.id, t.tweettext order by count
LIMIT 10;
END//

我一直报错

#1064 - 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 12

谁能找出错误..

最佳答案

您的查询在作为数据库级别的脚本执行时有效。

但是使用 PhpMyAdmin 您需要删除 delimiter 语句。

CREATE PROCEDURE getTweets (var1 varchar(100))
LANGUAGE SQL
SQL SECURITY DEFINER
COMMENT 'A procedure to return 20 least scored tweets based on the temp sessionid of the user'
BEGIN
SELECT count(ts.tweetid) as "count",t.id as "tweetid", t.tweettext as "tweet"
FROM tweets t
LEFT JOIN tweetscores ts ON t.id = ts.tweetid
where t.id not in (select distinct(tweetid) from tweetscores where temp_sessionid=var1)
group by t.id, t.tweettext order by count
LIMIT 10;
end

PhpMyAdmin 将为您完成剩下的工作。

关于mysql - 在 MySQL 中创建存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28062710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com