Oracle paging query SQL syntax

Source: Internet
Author: User

Oracle paging query SQL syntax classification: Oracle column 4850 people read comments (1) collect reports

-- 1: no order by statement. (Most efficient)
-- (After testing, this method has the lowest cost. Only one layer is nested, and the speed is the fastest! Even if the queried data volume is large, it is almost unaffected and the speed is still high !)
Select *
From (select rownum as rowno, T .*
From k_task t
Where flight_date between to_date ('20140901', 'yyyymmdd') and
To_date ('20140901', 'yyyymmdd ')
And rownum <= 20) table_alias
Where table_alias.rowno> = 10;

-- 2: Order by sorting. (Most efficient)
-- (After testing, this method slows down as the query range expands !)
Select *
From (select TT. *, rownum as rowno
From (select T .*
From k_task t
Where flight_date between to_date ('20140901', 'yyyymmdd') and
To_date ('20140901', 'yyyymmdd ')
Order by fact_up_time, flight_no) TT
Where rownum <= 20) table_alias
Where table_alias.rowno> = 10;

-- 3: no order by statement. (Method 1 is recommended)
-- (This method slows down as the query data size expands !)
Select *
From (select rownum as rowno, T .*
From k_task t
Where flight_date between to_date ('20140901', 'yyyymmdd') and
To_date ('20140901', 'yyyymmdd') table_alias
Where table_alias.rowno <= 20
And table_alias.rowno> = 10;
-- Table_alias.rowno between 10 and 100;

-- 4: there is an order by sorting Statement (method 2 is recommended)
-- (This method slows down as the query range expands !)
Select *
From (select TT. *, rownum as rowno
From (select *
From k_task t
Where flight_date between to_date ('20140901', 'yyyymmdd') and
To_date ('20140901', 'yyyymmdd ')
Order by fact_up_time, flight_no) TT) table_alias
Where table_alias.rowno between 10 and 20;

-- 5 alternative syntax. (Order by Statement)
-- (The syntax style is different from the traditional SQL syntax, which is not easy to read and understand. It is not recommended for standardization and unified standards .)
With partdata (
Select rownum as rowno, TT. * from (select *
From k_task t
Where flight_date between to_date ('20140901', 'yyyymmdd') and
To_date ('20140901', 'yyyymmdd ')
Order by fact_up_time, flight_no) TT
Where rownum <= 20)
Select * From partdata where rowno> = 10;

-- 6 alternative syntax. (No order by Statement)
With partdata (
Select rownum as rowno, T .*
From k_task t
Where flight_date between to_date ('20140901', 'yyyymmdd') and
To_date ('20140901', 'yyyymmdd ')
And rownum <= 20)
Select * From partdata where rowno> = 10;

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.