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;
有关oracle分页查询的sql语句大全,就介绍这些了,希望大家喜欢。