如何在MySQL中使用带参数的LIMIT指令?
像:
SELECT * FROM someTable LIMIT variable1, variable2;
答案 0 :(得分:6)
在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 = ""
可选地
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;
有关此here
的更多信息