Home >Database >Mysql Tutorial >关于MySQL的limit使用变量_MySQL

关于MySQL的limit使用变量_MySQL

WBOY
WBOYOriginal
2016-06-01 13:51:231347browse

初识MySql不知道limit后面怎么可以用变量动态的显示需要的记录,后来才发现可以这样做

CREATE PROCEDURE GetUser(_id int,_limit int)
BEGIN
PREPARE s1 FROM 'SELECT * FROM User WHERE Cityid=? ORDER BY sendtime DESC LIMIT ?';
set @a=_id;
set @b=_limit;
EXECUTE s1 USING @a,@b;
DEALLOCATE PREPARE s1;
END;

注意:需要传参数的地方一定要用"?"号,第一个FRom后面的语句要用''括起。

  

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn