Problem: I need write stored procedure(s) that will return result set of a single page of rows and the number of total rows.
Solution A: I create tw
In Oracle 12C you can use limit LIMIT
and OFFSET
for the pagination.
Example -
Suppose you have Table tab
from which data needs to be fetched on the basis of DATE
datatype column dt
in descending order using pagination.
page_size:=5
select * from tab
order by dt desc
OFFSET nvl(page_no-1,1)*page_size ROWS FETCH NEXT page_size ROWS ONLY;
Explanation:
page_no=1 page_size=5
OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY
- Fetch 1st 5 rows only
page_no=2 page_size=5
OFFSET 5 ROWS FETCH NEXT 5 ROWS ONLY
- Fetch next 5 rows
and so on.
Refrence Pages -
https://dba-presents.com/index.php/databases/oracle/31-new-pagination-method-in-oracle-12c-offset-fetch
https://oracle-base.com/articles/12c/row-limiting-clause-for-top-n-queries-12cr1#paging