数据库分页

分页的话题总是听热门的话题,不妨把分页做成存储过程吧,
这样在处理速度还有网络传输量上都有优势

以前的分页参见:
http://fengyanzhang.iteye.com/blog/1922161
http://fengyanzhang.iteye.com/blog/1921682
http://fengyanzhang.iteye.com/blog/1880275


关于各个数据库的分页代码如下:

sql语句分页,不同的数据库下的分页方案各不一样,下面是主流的三种数据库的分页sql:
sql server:
         String sql =
         "select top " + pageSize + " * from students where id not in" +

"(select top " + pageSize * (pageNumber-1) + " id from students order by id)" +

"order by id";

mysql:

         String sql =
         "select * from students order by id limit " + pageSize*(pageNumber-1) + "," + pageSize;
       
oracle:

         String sql =
          "select * from " + 
          (select *,rownum rid from (select * from students order by postime desc) where rid<=" + pagesize*pagenumber + ") as t" +
          "where t>" + pageSize*(pageNumber-1);

上述各种分页代码还只是比较初级的分页代码。

你可能感兴趣的:(oracle,sql,mysql,SQL Server)