MySQL 5.x: passing limits as stored procedure / function parameters
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;
Comments
One Comment on MySQL 5.x: passing limits as stored procedure / function parameters
-
web development company bangalore on
Mon, 9th May 2011 7:54 am
good article, Thanks for sharing the programming concept.
Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!





