ORACLE分頁查詢SQL文法

來源:互聯網
上載者:User

ORACLE分頁查詢SQL文法 分類: ORACLE專欄 2007-08-26 23:56 4850人閱讀 評論(1) 收藏 舉報

--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寫法)
--(文法風格與傳統的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;   

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.