获取分页数据的存储过程模版
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取分页数据的存储过程模版相关的知识,希望对你有一定的参考价值。
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);
以上是关于获取分页数据的存储过程模版的主要内容,如果未能解决你的问题,请参考以下文章