select /*+ first_row */*
    from TABLENAME
    where rowid in (select rid from (select rownum rno, rid
                                         from (select rowid rid from TABLENAME
                                                   order by FIELD1 desc)
                                         where rownum <= 300020 )
                        where rno >= 300010);
前提:表TABLENAME按FIELD1建索引。

解决方案 »

  1.   

    为什么要引入rowid?
    select rowid rid from TABLENAME order by FIELD1 desc 此句为什么FIELD1要desc?asc不行吗?
      

  2.   

    那只是一个例子。desc还是asc要根据业务需要。
    由于有索引,索引中有rowid,所以排序时只从索引中取出需要的rowid,再根据rowid读取记录的内容,这样最快。百万行的,只需要0.几秒就有结果。
    此外,排序字段必须是非空的,否则用不上索引。
      

  3.   

    最后一个问题,这句语句改成这样行不行?为什么?
    select /*+ first_row */*
        from TABLENAME
        where rowid in (select rid  from (select rowid rid from TABLENAME
                                                       order by FIELD1 desc)
                                             where rownum <= 300020 and rownum>=300010);
      

  4.   

    不行。rownum是伪列,where rownum>1的行是永远不存在的。