Home > Database > Mysql Tutorial > body text

关于MySQL的limit使用变量_MySQL

WBOY
Release: 2016-06-01 13:51:23
Original
1212 people have browsed it

初识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后面的语句要用''括起。

  

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!