Oracle分页查询

使用Oracle的row_num关键字

  select * from (
          select rownum r_num,a.* from  pf_message a   
         ) where r_num <=2;

总记录数 total_num =  count(*);

总页数 = 总记录数/每页显示条数

  total_pages =( total_num+per_page_num - 1) / per_page_num;
传过来的参数:  当前页数  current_page,每页显示条数 per_page_num

查询某一页sql条件:

  当前页面查询起始条件(当前页面第一条记录):row_num > (current_page - 1)*per_page_num;

  当前页面查询结束条件(当前页面最后一条记录):row_num <= current_page*per_page_num;

所以

  select * from (
          select rownum r_num,a.* from  pf_message a   
         ) where r_num >(current_page - 1)*per_page_num and r_num <= current_page*per_page_num;

 

    

  

 

posted @ 2015-01-28 15:16  轩辕风  阅读(184)  评论(0编辑  收藏  举报