Oracle Paging Query

Source: Internet
Author: User

The common Oracle paging query implementation methods are three, respectively, through RowNum, ROWID, or analysis function implementation, this article will be in my Project User_info table of the sub-table as an example, a brief description of the implementation of three kinds of paging:

--Create tablecreate table User_info (  user_id number      () not NULL,  NAME         VARCHAR2 (+),  pet_name     VARCHAR2 (+),  Head_ico     VARCHAR2 (255),  create_date  DATE not NULL)
1. According to rownum pagination

Select tt.* from (select ROWNUM RN, t.* from (select UI. USER_ID, Ui.name, UI. Pet_name, UI. Head_ico, UI. Create_date from the User_info UI ORDER by UI. Create_date DESC) T where ROWNUM < 600010) TT where TT. RN >= 600000;<span style= "color: #ff0000;" >--Execution Time: 1.981 sec </span>

2. According to ROWID pagination

SELECT UI. USER_ID, Ui.name, UI. Pet_name, UI. Head_ico, UI. Create_date from  user_info UI WHERE ROWID in (select Rid from                   (select ROWNUM RN, rids from                           (select ROWID rid
   from user_info                                   ORDER by Create_date DESC)                          where ROWNUM < 600010)                  where RN >= 600000) the order by UI. Create_date desc;<span style= "color: #ff0000;" >--Execution Time: 1.887 sec </span>

3. Paging based on analytic functions

SELECT * FROM  (select UI. USER_ID,               ui.name,               UI. Pet_name,               UI. Head_ico,               UI. Create_date,               row_number () over (the ORDER by UI. Create_date DESC) RK from          user_info UI) T WHERE T.rk < 600010 and   t.rk >= 600000<span style= "COLOR: #ff000 0; " >--Execution Time: 2.886 sec </span>

From the above three SQL we can find:

(1) Regardless of the way to achieve paging, is to use nested subqueries;

(2) Query the required fields are generally recommended to list the required fields, rather than through the method of SELECT * all detected, which will affect the efficiency of the query;

(3) The use of ROWID paging query efficiency is relatively high, rownum and analysis function respectively. Of course, for a table with a large amount of data, it may only be slow to meet performance requirements in this way, and it needs to be perfected by optimizing SQL or indexing.


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.