Common SQL Paging statements (Oracle)

Source: Internet
Author: User

Common Oracle Query statements

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!

The SQL statements are as follows:

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 <=) Table_alias
WHERE Table_alias. ROWNO >= 10;

2. There is an order by ordering the notation. (Highest efficiency)

After testing, this method will become more and more slow as the query scope expands!

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 <=) table_alias
where Table_alias.rowno >= 10;

3. No order by ordering. (It is recommended to use Method 1 instead)
This method will be more and more slow as the amount of query data expands!

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 and 100;

4. There is an order by ordering the notation. (It is recommended to use Method 2 instead)

This method will become more and more slow as the scope of the query expands!       

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 and 20;

5. Alternative syntax. (with order by notation)

This grammar style differs from the traditional SQL syntax and is not easy to read and understand, and is not recommended for standard and uniform standards. The code is posted here for your reference.

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. Alternative syntax. (no ORDER by notation)

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;

Common SQL Paging statements (Oracle)

Related Article

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.