2014-03-03 64 views
1

我收到此錯誤MySQL的存儲過程埃羅

#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 'lstart, lend; END IF; ELSE IF lstart = -1 THEN select count(*) a' at line 8"

上服務器,但在我的本地主機的phpmyadmin它正在創建沒有任何錯誤此創建存儲過程?

DELIMITER 
create procedure getallmedia(IN cat int(2), IN asc_desc varchar(5), IN lstart int(11), IN lend int(11)) 
BEGIN 
IF cat = -1 THEN 
    IF asc_desc = 'asc' THEN 
     IF lstart = -1 THEN 
      select count(*) as result from bc_media where id <> -1; 
     ELSE 
      select * from bc_media where id <> -1 limit lstart, lend; 
     END IF; 
    ELSE 
     IF lstart = -1 THEN 
      select count(*) as result from bc_media where category = cat; 
     ELSE 
      select * from bc_media where category = cat order by id desc limit lstart, lend; 
     END IF; 
    END IF; 
ELSE 
    IF asc_desc = 'asc' THEN 
     IF lstart = -1 THEN 
      select count(*) as result from bc_media where category = cat; 
     ELSE 
      select * from bc_media where category = cat limit lstart, lend; 
     END IF; 
    ELSE 
     IF lstart = -1 THEN 
      select count(*) as result from bc_media where category = cat; 
     ELSE 
      select * from bc_media where category = cat order by id desc limit lstart, lend; 
     END IF; 
    END IF; 
END IF; 
END 
DELIMITER ; 

幫我請:(

+0

一些mysql版本(較舊的版本)不支持動態限制....也許你的開發和生產mysql版本是不一樣的... – Hackerman

+0

檢查[SQL小提琴演示MySQL 5.5.32](http:// sqlfiddle.com/#!2/f51a9f/1) 。然後使用5.1.61版本的MySQL嘗試相同的代碼來重現問題。從文檔:「在存儲的程序中,LIMIT參數可以使用整數值例程參數或從MySQL 5.5.6開始的局部變量指定。」。請參見[13.2.9 SELECT語法](http://dev.mysql.com/doc/refman/5.5/en/select.html) – wchiquito

回答

0

我不知道,但是,在第一分隔符儘量把$$

而最後END放後$$