开发者

MySQL LIMIT with parameters

How to use LIMIT instruction with parameters in MySQL?

Like:

SELECT * F开发者_如何学PythonROM someTable LIMIT variable1, variable2;


Try this inside SP

SET @String1 = concat(concat(concat(concat("SELECT field1,field2 FROM table1 WHERE field3 = ",sp_var1," && field4 = "),sp_var2," LIMIT "),sp_Var_skip,","),sp_var_count); 
PREPARE Stmt FROM @String1; 
EXECUTE Stmt; 
SET @String1 = "" 

Alternatively

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

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

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

More information on this here

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜