首页 > 代码库 > 获取分页数据的存储过程模版
获取分页数据的存储过程模版
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);
获取分页数据的存储过程模版
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。