2015-01-21 91 views
0

我已经5.0.10创建存储过程在MySQL

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// 

我一直为在MySQL中创建一个存储过程以下语法收到错误

#1064 - 你有一个错误你的SQL语法; 检查对应于你的MySQL服务器版本在线路附近使用“//”正确的语法手册12

有谁能够发现错误..

+0

适合我。你如何执行它? – 2015-01-21 08:39:00

+0

尝试在下一行保留分隔符 – 2015-01-21 08:39:25

+0

@juergend只需点击phpmyadmin中的go按钮... – dakait 2015-01-21 08:52:35

回答

2

执行它的时候你的查询工作DB级别的脚本。

但是使用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的将完成剩下的为您服务。

+0

感谢您的时间和精力... – dakait 2015-01-21 13:10:40

0
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