2015-01-21 153 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