Oracle range query or paging query (reply to a netizen)

Source: Internet
Author: User

The Oracle query you mentioned is still very common. It is often used during project development. It is impossible to load large volumes of data to the memory at a time. This will use paging, paging uses the range I used. net Microsoft followers (oh, don't disagree! Java and. net in this industry, the battle of the tongue has not been closed), also use ORACLE you said this range query in SQL Server may be better achieved, because it has a top keyword. this is not to mention, mainly oracle. oracle has a rownum keyword. Its function is equivalent to SQL Server's top. rownum returns the internal row number of the table and queries the number of records, its row number will increase from 1 to the last record, and this increment is real-time. therefore, we cannot use the conventional idea to query.
For example, select * From tablename where rownum> = 1000 and rownum <= 10000 because the record has not been generated, the condition you give does not work at all, so it is null. but there is a solution. We may make a subquery to convert rownum into usable data.
Select rownum field_byname, table_byname. * From tablename table_byname and embed it into the following brackets
Select * from (select rownum field_byname, table_byname. * From tablename table_byname) A where a. field_byname> = 1000 and A. field_byname <= 10000 this method is easy to understand,
But the efficiency is not high. It queries all the data and then queries the rows between 1000 and 10000 from all the data. According to the Cartesian Product Principle, the redundancy is quite large. there is also a way to improve the preceding SQL, which is much more efficient.
Select * from (select rownum field_byname, table_byname. * From tablename table_byname
Where rownum <= 10000) A where a. field_byname >=1000

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.