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?)
精彩评论