rownum工作原理.
Rownum原理:
1 Oracle executes your query.
1.执行查询操作
2 Oracle fetches the first row and calls it row number 1.
2.将第一行的row num置为1
3 Have we gotten past row number meets the criteria? If no, then Oracle discards the row, If
yes, then Oracle return the row.
3.将得到的行的row num与条件相比较,如果不匹配,则抛弃行,如果匹配,则返回行
4 Oracle fetches the next row and advances the row number (to 2, and then to 3, and then to
4, and so forth).
4.oracle获取下一行,然后将rownum增1
5 Go to step 3.
5.返回第3步我的疑问是:如何理解 select rownum,name from emp where rownum>5;不返回行

解决方案 »

  1.   


    ---我的疑问是:如何理解 select rownum,name from emp where rownum>5;不返回行select rownum,name from emp where rownum>5 
    --这样写是错的 在里面只能是rownum<=nselect * from (select rownum rn,name from emp where rownum<=n)
    where rn>5 
    --嵌套才能这样的
      

  2.   

    ROWNUM是一个序列,是oracle数据库从数据文件或缓冲区中读取数据的顺序。它取得第一条记录则rownum值为1,第二条为2,依次类推。因为你用>时,因为从缓冲区中得到的第一条记录的rownum为1,不符合>5的条件,所以被删除,接着取下条,可是它的rownum还是1,又被删除,依次类推,便没有了数据。
      

  3.   

    2楼解释了,
    rownum是不能用来判断rownum>n的,
    如果想用rownum大于几判断的话需要子查询
    select rm,字段1 from (select rownum rm,字段1 from 表名) where rm>5;
      

  4.   


    恩 学习了 rownum>=1时,全部记录,但是改为rownum>1就没有记录了。