Retrieve records by page in Oracle

Source: Internet
Author: User

How to extract records by PAGE
Method 1: The rownum pseudo column of Oracle returns the row serial number of the query.
For example, you can use
Select * From tablename where rownum <= 10
However, to return 11th-20th records, try the following statement:
Select * From tablename where rownum <= 20 and rownum> = 11;
This person reported an error. Returns 0 records. Because rownum is a pseudo column, the> = condition cannot be used.
Use the following method to query 11th-20th records
Select * from
(Select rownum RN, T. * From tablename t where rownum <= 20) Where rn> = 11;
Method 2: Use the analysis function row_number to implement Paging
Select * from (select row_number () over (order by ID) Rn, T. * From tablename T)
Where rn between 11 and 20;
Method 3: Use the set operation minus to implement Paging
Select * From tablename where rownum <= 20 minus
Select * From tablename where rownum <11;
Comment: method 1 is fast when searching for the first few pages. However, when the data volume is large, the last few pages are slow.
Method 2 the query efficiency is relatively stable and is recommended.
Method 3 is applicable only when the query result is less than 200 rows. If the number of records is large, Oracle errors may occur. Therefore, use it with caution.

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.