Solve the paging error caused by inconsistent sorting fields in oracle sorting by rownum

Source: Internet
Author: User

Solve the paging error caused by inconsistent sorting fields using rownum in oracle. Recently, when I wrote a list component ulynlist, I detected a problem and recorded it here. Today, when I called the list component, I tried to lower the number of items and each page. When I finished the plug-in of the paging foot, I was very happy, suddenly, I found out how the data was always written by the front-end plug-in. Later, I went to the SQL statements in the console and cut out the SQL statements for execution. I found that from 9 to 13 is the same record.

1 SELECT * FROM (select. *, rownum rn from (2 select t. * from T_CAR_INFO t WHERE t. del = '0' AND t. id = '003 '3 order by CREATE_TIME desc) a where rownum <= 10) where rn> = 10

 

Normally, this SQL statement is difficult to find out what is wrong. In general, the CREATE_TIME in our small-traffic system is often unique, so it is really difficult to find out. I use CREATE_TIMEDESC for sorting, but the value of this field is copied and pasted because it is filled by the database record. Many records have the same value. This is a typical case where the order by field value is not unique, resulting in confusion in paging records. How can this problem be solved? In fact, it is very simple. You only need to add a field with unique values during sorting. Preferably id. Changed to the following to find that everything is normal:
1 SELECT * FROM (select. *, rownum rn from (2 select t. * from T_CAR_INFO t WHERE t. del = '0' AND t. id = '003 '3 order by CREATE_TIME desc, id) a where rownum <= 10) where rn> = 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.