开发者

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

开发者 https://www.devze.com 2023-02-28 00:25 出处:网络
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

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

精彩评论

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