本文實(shí)例匯總了Oracle實(shí)現(xiàn)分頁(yè)查詢的SQL語(yǔ)法,整理給大家供大家參考之用,詳情如下:
1.無(wú)ORDER BY排序的寫法。(效率最高)
經(jīng)過(guò)測(cè)試,此方法成本最低,只嵌套一層,速度最快!即使查詢的數(shù)據(jù)量再大,也幾乎不受影響,速度依然!
sql語(yǔ)句如下:
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排序的寫法。(效率最高)
經(jīng)過(guò)測(cè)試,此方法隨著查詢范圍的擴(kuò)大,速度也會(huì)越來(lái)越慢!
sql語(yǔ)句如下:
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.無(wú)ORDER BY排序的寫法。(建議使用方法1代替)
此方法隨著查詢數(shù)據(jù)量的擴(kuò)張,速度會(huì)越來(lái)越慢!
sql語(yǔ)句如下:
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代替)
此方法隨著查詢范圍的擴(kuò)大,速度也會(huì)越來(lái)越慢!
sql語(yǔ)句如下:
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.另類語(yǔ)法。(有ORDER BY寫法)
該語(yǔ)法風(fēng)格與傳統(tǒng)的SQL語(yǔ)法不同,不方便閱讀與理解,為規(guī)范與統(tǒng)一標(biāo)準(zhǔn),不推薦使用。此處貼出代碼供大家參考之用。
sql語(yǔ)句如下:
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.另類語(yǔ)法 。(無(wú)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;
相信本文所述代碼能夠?qū)Υ蠹矣幸欢ǖ膮⒖冀梃b價(jià)值。
您可能感興趣的文章:- Oracle 左連接(+)加號(hào)用法及常用語(yǔ)法之間的關(guān)系
- Oracle存儲(chǔ)過(guò)程循環(huán)語(yǔ)法實(shí)例分析
- MySQL與Oracle的語(yǔ)法區(qū)別詳細(xì)對(duì)比
- Oracle存儲(chǔ)過(guò)程基本語(yǔ)法介紹
- SQLServer 2005 和Oracle 語(yǔ)法的一點(diǎn)差異小結(jié)
- Oracle存儲(chǔ)過(guò)程入門學(xué)習(xí)基本語(yǔ)法
- oracle基礎(chǔ)語(yǔ)法詳解