How to realize paging query by Oracle
This article is about how Oracle implements paging queries. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
What is a paged query
Paging query is to display the result set of query by page. For example, a result set has 1W rows and 100 database rows per page. And you get the result set on page 2.
Why do you want to query in pages
If a result set has dozens of W rows, it must not be displayed on one page. At the same time, displaying database records needs to be loaded into memory, while displaying large amounts of data consumes more memory.
We can use paging queries for the following purposes:
In order to accurately locate the contents of the result set
In order to save memory
In order to display moderate data in limited page space.
How to realize paging query
EMP table using Oracle
Select * from (select rownum rn, e. * from (select * from EMP) e)
The results are as follows:
The source code for paging query is as follows:
Select * from (select rownum rn, e. * from (select * from EMP) e) where rn > pageSize * (page-1) and rn 5 and rn 5 and rn