zoukankan      html  css  js  c++  java
  • 数据库分页

    1.分页的概念

      从数据库中查询出的记录分页显示。

    2.分页的目的

    • 美观
    • 提高效率

    3.分页方式

    • 假分页
    • 真分页

      区别:

        假分页是将需要的记录全部查询出来一次加载在内存中,然后从内存中取出一定的记录条数进行显示。

        真分页是每次真的从数据库中取出一定的记录条数。

        显然,假分页更加消耗内存,在数据量很大时效率很低。因此,只有在数据量很小的时候才会考虑假分页,在实际应用中应用很多的是真分页。

    4.如何分页

     select * from(
      select e.*,rownum r from(
        select * from t_temp order by empno
      )e
    )where r<=end and r>=begin

    已知条件
    1.当前页currentPage
    2.每页显示的最大行pageSize

    容易推出
    1.本页最后一行=currentPage * pageSize
    2.上页最后一行=( currentPage - 1 ) * pageSize

    推导公式
    1.本页起始行
    begin =上页最后一行 + 1
    =( currentPage - 1 ) * pageSize + 1
    2.本页终止行
    end =本页最后一行
    =currentPage * pageSize

    5.总结

    (1)数据库分页分为两种:真分页和假分页。实际应用中比较多的是真分页。

    (2)真分页计算公式:

      本页起始行 = ( 当前页 - 1 ) * 每页显示最大行 + 1;

      本页终止行 = 当前页 * 每页显示最大行

    (3)分页查询SQL语句:

      select * from(

       select e.*,rownum r from(           ---->step2:得到虚表e的「行号」和「全部记录」,便于分页  

        select * from emp order by empno     ---->step1:查询出所有记录并排序【虚表e】

       )e

      )where r>=begin and r<=end          ---->step3:按照分页条件查询最终结果(注意将begin和end用公式替换)

     

  • 相关阅读:
    android29
    android28
    android27
    android26
    Dynamics CRM2011 MspInstallAction failed when installing an Update Rollup
    Dynamics CRM Import Solution Attribute Display Name description is null or empty
    The service cannot be activated because it does not support ASP.NET compatibility
    IIS部署WCF报 无法读取配置节“protocolMapping”,因为它缺少节声明
    Unable to access the IIS metabase.You do not have sufficient privilege
    LM算法与非线性最小二乘问题
  • 原文地址:https://www.cnblogs.com/helloIT/p/5202869.html
Copyright © 2011-2022 走看看