--1:無ORDER BY排序的寫法。(效率最高) ­
--(經過測試,此方法成本最低,只嵌套一層,速度最快!即使查詢的數據量再大,也幾乎不受影響,速度依然!) ­
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排序的寫法。(效率最高) ­
--(經過測試,此方法隨著查詢范圍的擴大,速度也會越來越慢哦!) ­
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代替) ­
--(此方法隨著查詢數據量的擴張,速度會越來越慢哦!) ­
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代替) ­
--(此方法隨著查詢范圍的擴大,速度會越來越慢哦!) ­
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寫法) ­
--(語法風格與傳統(tǒng)的SQL語法不同,不方便閱讀與理解,為規(guī)范與統(tǒng)一標準,不推薦使用。) ­
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; ­
-
更多信息請查看IT技術專欄