MySQL 5.x (at least 5.0.15 and earlier versions) does not allow using variables or procedure formal parameters with LIMIT. Here is a workaround:
CREATE PROCEDURE sp (
IN LimitStart_ INT,
IN LimitCnt_ INT
)
BEGIN
SET @lim = CONCAT(' LIMIT ', LimitStart_, ',', LimitCnt_);
SET @q = "SELECT mycol FROM mytable";
SET @q = CONCAT(@q, @lim);
PREPARE st FROM @q;
EXECUTE st;
DEALLOCATE PREPARE st;
END;
No comments:
Post a Comment