Oracle实现分页查询的SQL语法汇总
程序员文章站
2022-06-05 21:29:36
本文实例汇总了oracle实现分页查询的sql语法,整理给大家供大家参考之用,详情如下:
1.无order by排序的写法。(效率最高)
经过测试,此方法成本最低,只嵌...
本文实例汇总了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;
相信本文所述代码能够对大家有一定的参考借鉴价值。
上一篇: C语言--指针详解
下一篇: SQL查询语句精华使用简要第1/2页