码迷,mamicode.com
首页 > 其他好文 > 详细

获取分页数据的存储过程模版

时间:2017-01-28 20:23:32      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:isa   font   ring   rom   locate   where   ges   log   bit   

drop procedure if exists proc_getPageRecords;
create procedure proc_getPageRecords(
in tableName varchar(30),  -- like:Student
in selectPart varchar(200),  -- like:StuId,Name
in wherePart varchar(200),  -- like:StuId=4&&Name in("ff","bc","dd")
in sortClm varchar(30),  -- like CreateTime
in isAscSort bit,
in pageIndex int,  -- like:1  // 第二页,其实这里可以直接用startRow,pageSize换成rowCount
in pageSize int)  -- like:100   // 每页100条
BEGIN
set @startRow = pageIndex*pageSize;

if(isAscSort) THEN
set @sortPart = CONCAT("order by ",sortClm," asc");  -- order by CreateTime asc
ELSE
set @sortPart = CONCAT("order by ",sortClm," desc");
end if;
/* select StuId,Name from Student where StuId=4&&Name in("ff","bc","dd") order by CreateTime asc limit 100,100;*/
set @sqlString = CONCAT("select ",selectPart," from ",tableName," where ",wherePart," ",@sortPart," limit ",@startRow,",",pageSize,";");
prepare sqlstmt from @sqlString;
execute sqlstmt;
DEALLOCATE PREPARE sqlstmt;
END

call proc_getPageRecords("Student","*","Name=朱七","CreateTime",0,0,2);

 

获取分页数据的存储过程模版

标签:isa   font   ring   rom   locate   where   ges   log   bit   

原文地址:http://www.cnblogs.com/silentdoer/p/6354445.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!