Oracle paging Solution

Source: Internet
Author: User

After finishing the project yesterday, I asked the test to test it. The test said that paging query does not seem to work. After Turning to page 4th, the data results will be the same.
At that time, I was puzzled. It was impossible. The paging component should be good. Why is there a problem. With questions, I opened my ide and ran it on my own machine, which really caused a problem.
If you have any questions, you need to find the problem.:
First, print the two SQL statements with the same query results to the database for execution:
Sql1:
Copy codeThe Code is as follows:
Select *
From (select t. *, rownum rn
From (select t_e_id, t_e_name, t_e_tel, t_e_areacode
From (select t. eid t_e_id,
T. ename t_e_name,
T. etel t_e_tel,
T. areaid t_e_areacode,
T. biz_delete_time,
Decode (areaid, '000000', '0', '1') orderseq
From vr_enterprise t
Where t. eid not in (select eid from t_biz_erelation ))
Order by orderseq, biz_delete_time nulls last) t
Where rownum <25)
Where rn> = 19
Sql2:
Select *
From (select t. *, rownum rn
From (select t_e_id, t_e_name, t_e_tel, t_e_areacode
From (select t. eid t_e_id,
T. ename t_e_name,
T. etel t_e_tel,
T. areaid t_e_areacode,
T. biz_delete_time,
Decode (areaid, '000000', '0', '1') orderseq
From vr_enterprise t
Where t. eid not in (select eid from t_biz_erelation ))
Order by orderseq, biz_delete_time nulls last) t
Where rownum <18)
Where rn> = 12

The result shows that most rows are the same.
To locate the problem, you only need to simplify the SQL statement step by step.
As a result, the data changed when where rownum <18. Why does the result change when a where condition is added?
It means you cannot figure it out .....
No way. I have to explain it to baidu. baidu has been around for a long time .....
Later, my colleague said, try another method, so he changed the method as follows:
Copy codeThe Code is as follows:
Select *
From (select t. *, rownum rn
From (select t_e_id, t_e_name, t_e_tel, t_e_areacode
From (select t. eid t_e_id,
T. ename t_e_name,
T. etel t_e_tel,
T. areaid t_e_areacode,
T. biz_delete_time,
Decode (areaid, '000000', '0', '1') orderseq
From vr_enterprise t
Where t. eid not in (select eid from t_biz_erelation ))
Order by orderseq, biz_delete_time nulls last) t) m
Where m. rn> = 1 and m. rn <25

This method works well, and it works well. The key is why the previous method doesn't work? The problem should be solved.
It seems that baidu does not work. You have to change to google search. Google search is always favored by the china government wall. There is no way to solve this problem. You have to find a chrome plug-in on the Internet.
Look for it to find, in oracle ask tom, tom detailed introduction of rownum usage, Here http://www.oracle.com/technetwork/issue-archive/2006/06-sep/o56asktom-086197.html
One important thing about using this pagination query is that the order by statement shocould order by something unique. if what you are ordering by is not unique, you should add something to the end of the order by to make it so.
When we see this sentence, we still need to add the uniqueness of order by when using order by, otherwise rownum will have a problem. Wow, haha. I am so happy that I am not willing to bother myself. I have found the crux of the problem. Of course, I will solve it.
This right is a troubleshooting experience. It is recorded that google is much more powerful than baidu. It will be easier to learn English in the future. Otherwise, the problem will not be solved.

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.