MySQL的分页查询及Oracle分页查询
MySQL: Select ... from ...where ...order by...limit start,pageNum 例:比如从 10 取 20 个数据 select * from table limit 10,20 String sql = "select * from addressbook where limit "+(currentPage-1)*pageRecord +","+pageRecord +""; //select * from 表名 【条件】limit M,N; //M为从第几个记录开始,比如每页显示条记录,第二页就必须从第条记录开始 //N每页读几个数据 Oracle:select * from (select rownum,name from table where rownum <= endIndex ) where rownum > startIndex 例:例如从表 Sys_option(主键为 sys_id)中从 10 条记录还是检索 20 条记录,语句如下: SELECT * FROM (SELECT ROWNUM R,t1.* From Sys_option t1 where rownum <= 30 ) t2 Where t2.R > 10; String sqls = "select * from ( select rownum rn,t.* from addressbook t where rownum <= "+currentPage*pageRecord+" ) where rownum > "+(currentPage -1)*pageRecord;
注意:(其中的分页情况不一样,就是参数限制不一样)
1、MySQL的分页实现中limit()参数一个是是从第几条记录开始,第二条记录是每页显示条数
2、Oracle的分页查询中: rownum > 起始记录 , rownum < 末位置记录