首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

分页存储过程个人小结

2012-08-21 
分页存储过程个人总结初学Mysql两天内写出了分页的存储过程,代码如下:CREATE DEFINER`root`@`localhost`

分页存储过程个人总结
初学Mysql两天内写出了分页的存储过程,代码如下:

CREATE DEFINER=`root`@`localhost` PROCEDURE `getAllpaged`(IN pageSize INT,IN currPage INT)    DETERMINISTICBEGINdeclare Idmax int;declare lowerbound int;declare maxpage int;declare upperbound int;select max(id) from ftp into Idmax;//选出最大IDselect ceiling(1.0*Idmax/pageSize) into maxPage;//选出最后页的页号if (currPage>0 and currPage<=maxPage) thenselect 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;elseset lowerbound=Idmax-pageSize;SELECT * FROM ftp WHERE id>lowerbound AND id<=Idmax order by id desc;//若在范围以外则返回第一页end if;END

后知后觉max(id)换成[b]count(*)好些

热点排行