0

I need to display rows 256 to 700 from a table 'customers'. Customers table can have rows in the millions. Customers table has primary key defined on 'cust_id'

  • http://stackoverflow.com/questions/470542/how-do-i-limit-the-number-of-rows-returned-by-an-oracle-query-after-ordering – André Schild May 21 '13 at 21:54
  • Do you mean rows 256 to 700 when the rows are counted in some order, or do you mean `cust_id` should be between 256 and 700? That makes a huge difference. – jpmc26 May 21 '13 at 21:58

1 Answers1

1

Probably the fastest way is something like this:

select c.*
from (select rownum as seqnum, c.*
      from customers c
      where rownum <= 700
     ) c
where seqnum >= 256;

The only caveat is that the order of the rows is not defined in a select query. To get things in the right order, you should use:

select c.*
from (select rownum as seqnum, c.*
      from (select c.*
            from customers c
            order by cust_id
           ) c
      where rownum <= 700
     ) c
where seqnum >= 256;
Gordon Linoff
  • 1,122,135
  • 50
  • 484
  • 624