rownum只可以用<=来操作,不可以用>=

解决方案 »

  1.   

    select * from (select rownum id,t.* from (select * from music  ORDER BY classid DESC) t
    where rownum<20) tt where tt.id>10;
      

  2.   

    从我的测试来看,没有任何问题.测试如下:SQL> set autotrace traceonly 
    SQL> set timing on
    SQL> select * from 
      2  (
      3      select rownum rm,a.* from (select * from fnd_user) a where rownum<=&maxv
      4  )
      5  where rm>=&minv
      6  /
    输入maxv的值: 10
    原值   3:    select rownum rm,a.* from (select * from fnd_user) a where rownum<=&maxv
    新值   3:    select rownum rm,a.* from (select * from fnd_user) a where rownum<=10
    输入minv的值: 3
    原值   5:where rm>=&minv
    新值   5:where rm>=3已选择8行。实际:3172Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=5 Card=390 Bytes=301
              860)   1    0   VIEW (Cost=5 Card=390 Bytes=301860)
       2    1     COUNT (STOPKEY)
       3    2       TABLE ACCESS (FULL) OF 'FND_USER' (Cost=5 Card=390 Byt
              es=83460)Statistics
    ----------------------------------------------------------
              0  recursive calls
              4  db block gets
              2  consistent gets
              6  physical reads
              0  redo size
           3550  bytes sent via SQL*Net to client
            308  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              8  rows processed
      

  3.   

    呵呵,对啊。
    这也就是我的问题所在,因为我把同样的SQL发给别人帮忙测试过,在他的环境下是可以的。而为什么我的9i反而不行呢,是否有其他参数的控制。
      

  4.   

    可能是Oracle在某些因素下不稳定的表现吧