How to extract records by PAGE
Method 1: The rownum pseudo column of Oracle returns the row serial number of the query.
For example, you can use
Select * From tablename where rownum <= 10
However, to return 11th-20th records, try the following statement:
Select * From tablename where rownum <= 20 and rownum> = 11;
This person reported an error. Returns 0 records. Because rownum is a pseudo column, the> = condition cannot be used.
Use the following method to query 11th-20th records
Select * from
(Select rownum RN, T. * From tablename t where rownum <= 20) Where rn> = 11;
Method 2: Use the analysis function row_number to implement Paging
Select * from (select row_number () over (order by ID) Rn, T. * From tablename T)
Where rn between 11 and 20;
Method 3: Use the set operation minus to implement Paging
Select * From tablename where rownum <= 20 minus
Select * From tablename where rownum <11;
Comment: method 1 is fast when searching for the first few pages. However, when the data volume is large, the last few pages are slow.
Method 2 the query efficiency is relatively stable and is recommended.
Method 3 is applicable only when the query result is less than 200 rows. If the number of records is large, Oracle errors may occur. Therefore, use it with caution.