Paging Queries for Oracle

Source: Internet
Author: User

--1: No ORDER by ordering. (Highest efficiency)
--(after testing, this method is the lowest cost, nesting only one layer, the fastest!) Even if the amount of data queried is large, and almost unaffected, the speed remains! )

SELECT *   from(SELECTROWNUM asRowno, T.*           fromEMP TWHEREHire_datebetweenTo_date ('20060501','YYYYMMDD')                              andTo_date ('20060731','YYYYMMDD')            andROWNUM<=  -) Table_aliasWHERETable_alias.rowno>= Ten;

--2: There is an order by ordering the notation. (Highest efficiency)
--(after testing, this method as the query scope expands, the speed will be more and more slow Oh!) )

SELECT *   from(SELECTTt.*, ROWNUM asRowno from(SELECTT.*                     fromEMP TWHEREHire_datebetweenTo_date ('20060501','YYYYMMDD')                                        andTo_date ('20060731','YYYYMMDD')                ORDER  byCreate_timeDESC, emp_no) TTWHEREROWNUM<=  -) Table_aliasWHERETable_alias.rowno>= Ten;

--3: No ORDER by ordering. (It is recommended to use Method 1 instead)
--(this method with the query data volume expansion, the speed will be more and more slow Oh!) )

SELECT *   from(SELECTROWNUM asRowno, T.*           fromK_task TWHEREFlight_datebetweenTo_date ('20060501','YYYYMMDD')                                andTo_date ('20060731','YYYYMMDD')) Table_aliasWHERETable_alias.rowno<=  -  andTable_alias.rowno>= Ten;

--table_alias. ROWNO between and 100;

--4: There is an order by ordering the notation. (It is recommended to use Method 2 instead)
--(This method will be more and more slow as the scope of the query expands!) )

SELECT *   from(SELECTTt.*, ROWNUM asRowno from(SELECT *                   fromK_task TWHEREFlight_datebetweenTo_date ('20060501','YYYYMMDD')                                          andTo_date ('20060531','YYYYMMDD')                ORDER  byFact_up_time, Flight_no) TT) Table_aliasWHERETable_alias.rownobetween Ten  and  -;

--5 Alternative Grammar. (with order by notation)
--(the grammatical style differs from the traditional SQL syntax, it is inconvenient to read and understand, and is not recommended for standard and uniform standards.) )

 withPartdata as     (        SELECTROWNUM asRowno, TT.*           from(SELECT *                     fromK_task TWHEREFlight_datebetweenTo_date ('20060501','YYYYMMDD')                                          andTo_date ('20060531','YYYYMMDD')               ORDER  byFact_up_time, Flight_no) TTWHEREROWNUM<=  -)SELECT *   fromPartdataWHERERowno>= Ten;

--6 Alternative Grammar. (no ORDER by notation)

 withPartdata as     (        SELECTROWNUM asRowno, T.*           fromK_task TWHEREFlight_datebetweenTo_date ('20060501','YYYYMMDD')                               andTo_date ('20060531','YYYYMMDD')            andROWNUM<=  -)SELECT *   fromPartdataWHERERowno>= Ten;

Paging Queries for Oracle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.