Kaan Mutlu's Blog

How to limit the number of rows with both lower and upper bounds returned by an Oracle query after ordering?

Advertisements

select * from (
  select a.*, ROWNUM rnum from (
    <select statement with order by clause>
  ) a where rownum <= MAX_ROW
) where rnum >= MIN_ROW

 
 
How to retrieve only the Nth row from a table?


select * from (
  select a.*, ROWNUM rnum from (
    <select statement with order by clause>
  ) a where rownum <= Nth_ROW
) where rnum >= Nth_ROW

 
 
Starting with Oracle 12c there is a syntax available to limit rows or start at offsets.

Resource: http://stackoverflow.com/questions/470542/how-do-i-limit-the-number-of-rows-returned-by-an-oracle-query-after-ordering

Advertisements