**
一、效率高的寫法
**
1.無ORDER BY排序的寫法。(效率最高)
(經過測試,此方法成本最低,只巢狀一層,速度最快!即使查詢的資料量再大,也幾乎不受影響,速度依然!)
SELECT *
FROM (SELECT ROWNUM AS rowno, t.*
FROM emp t
WHERE hire_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 emp t
WHERE hire_date BETWEEN TO_DATE ('20060501', 'yyyymmdd')
AND TO_DATE ('20060731', 'yyyymmdd')
ORDER BY create_time DESC, emp_no) tt
WHERE ROWNUM <= 20) table_alias
WHERE table_alias.rowno >= 10;1234567891011121314151617
**
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30345407/viewspace-2692212/,如需轉載,請註明出處,否則將追究法律責任。