首页 > 数据库 > oracle

Oracle实现分页查询的SQL语法汇总

admin oracle 2022-02-09 22:04:25 Oracle   分页查询   SQL   语法"

本文实例汇总了Oracle实现分页查询的SQL语法,整理给大家供大家参考之用,详情如下:

1.无ORDER BY排序的写法。(效率最高)

经过测试,此方法成本最低,只嵌套一层,速度最快!即使查询的数据量再大,也几乎不受影响,速度依然!

sql语句如下:

SELECT *
 FROM (Select ROWNUM AS ROWNO, T.*
      from k_task T
     where Flight_date between to_date('20060501', 'yyyymmdd') and
        to_date('20060731', 'yyyymmdd')
      AND ROWNUM <= 20) TABLE_ALIAS
WHERE TABLE_ALIAS.ROWNO >= 10;

2.有ORDER BY排序的写法。(效率最高)

经过测试,此方法随着查询范围的扩大,速度也会越来越慢!

sql语句如下:

SELECT *
 FROM (SELECT TT.*, ROWNUM AS ROWNO
      FROM (Select t.*
          from k_task T
          where flight_date between to_date('20060501', 'yyyymmdd') and
             to_date('20060531', 'yyyymmdd')
          ORDER BY FACT_UP_TIME, flight_no) TT
     WHERE ROWNUM <= 20) TABLE_ALIAS
where TABLE_ALIAS.rowno >= 10;

3.无ORDER BY排序的写法。(建议使用方法1代替)

此方法随着查询数据量的扩张,速度会越来越慢!

sql语句如下:

SELECT *
 FROM (Select ROWNUM AS ROWNO, T.*
      from k_task T
     where Flight_date between to_date('20060501', 'yyyymmdd') and
        to_date('20060731', 'yyyymmdd')) TABLE_ALIAS
WHERE TABLE_ALIAS.ROWNO <= 20
  AND TABLE_ALIAS.ROWNO >= 10;
TABLE_ALIAS.ROWNO between 10 and 100;

4.有ORDER BY排序的写法.(建议使用方法2代替)

此方法随着查询范围的扩大,速度也会越来越慢!

sql语句如下:

SELECT *
 FROM (SELECT TT.*, ROWNUM AS ROWNO
      FROM (Select *
          from k_task T
          where flight_date between to_date('20060501', 'yyyymmdd') and
             to_date('20060531', 'yyyymmdd')
          ORDER BY FACT_UP_TIME, flight_no) TT) TABLE_ALIAS
where TABLE_ALIAS.rowno BETWEEN 10 AND 20;

5.另类语法。(有ORDER BY写法)

该语法风格与传统的SQL语法不同,不方便阅读与理解,为规范与统一标准,不推荐使用。此处贴出代码供大家参考之用。

sql语句如下:

With partdata as(
 SELECT ROWNUM AS ROWNO, TT.* FROM (Select *
         from k_task T
         where flight_date between to_date('20060501', 'yyyymmdd') and
            to_date('20060531', 'yyyymmdd')
         ORDER BY FACT_UP_TIME, flight_no) TT
  WHERE ROWNUM <= 20)
  Select * from partdata where rowno >= 10;

6.另类语法 。(无ORDER BY写法)

With partdata as(
 Select ROWNUM AS ROWNO, T.*
  From K_task T
  where Flight_date between to_date('20060501', 'yyyymmdd') and
     To_date('20060531', 'yyyymmdd')
   AND ROWNUM <= 20)
  Select * from partdata where Rowno >= 10; 

相信本文所述代码能够对大家有一定的参考借鉴价值。

版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。
本文地址:/shujuku/oracle/99015.html

留言与评论(共有 0 条评论)
   
验证码:

潘少俊衡

| 桂ICP备2023010378号-4

Powered By EmpireCMS

爱享小站

中德益农

谷姐神农

环亚肥料

使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

感谢潘少俊衡友情技术支持