Rownum paging in Oracle Database

Source: Internet
Author: User

In the project test, the tester finds that when the query result list is displayed on multiple pages, some data is repeatedly displayed on several pages, and some are not displayed at one time. After analyzing the SQL, the original problem lies in the rownum paging. In Oracle, rownum is used for paging, Which is previously written as follows:

Select * from
(Select a. *, rownum rn from table a where condition) B
Where B. rn between 1 and 20;

When querying a single table, the results will not be displayed on the page, but when multiple tables are joined, rownum will be messy. Now we will change it to the following method: sort by specified fields and then get rownum, in this way, the results of each query are consistent:

Select * from
(Select a. *, rownum rn from
(Select * from table c, table1 d where condition order by c. id desc)
) B where B. rn between 1 and 20

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.