开发者

Can i use parameter for mysql "limit start, count"

I want to use stored proced开发者_运维技巧ure parameter as start and count in MySQL limit. But it seems limit only accepts constant values. How can i construct a sql in which start and limit is stored procedure parameter?


I really dont know, but I just feel like this will work for you. [Untested]

DELIMITER $ 
CREATE PROCEDURE `tmp`() 
BEGIN 
PREPARE STMT FROM "SELECT * FROM yourTable LIMIT ?,?"; 
END$ 
DELIMITER; 

SET @a=2; 
SET @b=1; 

CALL tmp(); 
EXECUTE STMT USING @a, @b; 


You can also set the limit, offset and so on as a Java Prepared Statement parameter. Just try it out. (We're talking about Java, right?)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜