Mysql
 sql >> Datenbank >  >> RDS >> Mysql

MySQL LIMIT mit Parametern

Versuchen Sie dies innerhalb von 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 = "" 

Alternativ

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; 

Weitere Informationen dazu hier