浏览 2949 次
锁定老帖子 主题:分页存储过程个人总结
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-02-11
CREATE DEFINER=`root`@`localhost` PROCEDURE `getAllpaged`(IN pageSize INT,IN currPage INT) DETERMINISTIC BEGIN declare Idmax int; declare lowerbound int; declare maxpage int; declare upperbound int; select max(id) from ftp into Idmax;//选出最大ID select ceiling(1.0*Idmax/pageSize) into maxPage;//选出最后页的页号 if (currPage>0 and currPage<=maxPage) then select Idmax-pageSize*currPage into lowerbound; select Idmax-pageSize*(currPage-1) into upperbound;//实现倒选 SELECT * FROM ftp WHERE id>lowerbound AND id<=upperbound order by id desc; else set lowerbound=Idmax-pageSize; SELECT * FROM ftp WHERE id>lowerbound AND id<=Idmax order by id desc; //若在范围以外则返回第一页 end if; END 后知后觉max(id)换成[b]count(*)好些 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |