Paginating Results with the Oracle DB
The basic idea is to wrap your query with two outer SELECTs. Each one will limit the result's
rownum
property:select
*
from (
select
raw_sql_.*, rownum raw_rnum_
from
(<YOUR SQL HERE>) raw_sql_
where
rownum <= <UPPER LIMIT>
)
where
raw_rnum_ > <LOWER LIMIT>
Where <UPPER LIMIT> is the upper row number you want, and <LOWER LIMIT> is the initial row offset. So say you want to return results 11 - 20 from this query:
SELECT * FROM news_stories ORDER BY date_created DESC
Your query would look like this:
select
*
from (
select
raw_sql_.*, rownum raw_rnum_
from
(SELECT * FROM news_stories ORDER BY date_created DESC) raw_sql_
where
rownum <= 20
)
where
raw_rnum_ > 10