oracle 中的 rownum
2010-10-22 09:02
176 查看
在Oracle中,要按特定条件查询前N条记录,用个rownum就搞定了。
select * from emp where rownum <= 5
而且书上也告诫,不能对rownum用">",这也就意味着,如果你想用
select * from emp where rownum > 5
则是失败的。要知道为什么会失败,则需要了解rownum背后的机制:
1 Oracle executes your query.
2 Oracle fetches the first row and calls it row number 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.
4 Oracle fetches the next row and advances the row number (to 2, and then to 3, and then to 4, and so forth).
5 Go to step 3.
了解了原理,就知道rownum>不会成功,因为在第三步的时候查询出的行已经被丢弃,第四步查出来的rownum仍然是1,这样永远也不会成功。
同样道理,rownum如果单独用=,也只有在rownum=1时才有用。
select * from emp where rownum <= 5
而且书上也告诫,不能对rownum用">",这也就意味着,如果你想用
select * from emp where rownum > 5
则是失败的。要知道为什么会失败,则需要了解rownum背后的机制:
1 Oracle executes your query.
2 Oracle fetches the first row and calls it row number 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.
4 Oracle fetches the next row and advances the row number (to 2, and then to 3, and then to 4, and so forth).
5 Go to step 3.
了解了原理,就知道rownum>不会成功,因为在第三步的时候查询出的行已经被丢弃,第四步查出来的rownum仍然是1,这样永远也不会成功。
同样道理,rownum如果单独用=,也只有在rownum=1时才有用。
相关文章推荐
- Oracle查询语句中rownum与rowid的不同之处分析
- Oracle的rownum原理和使用
- Oracle中rownum的用法
- Oracle中rownum的使用
- 菜鸟上路之oracle中rowid和rownum的使用 笔记整理
- Oracle 中 rownum 的用法
- 在Oracle中rownum的使用
- Oracle中rownum的说明及使用技巧
- oracle中rownum和row_number()
- 浅淡SqlServer的Top与Oracle的RowNum
- oracle使用rownum进行分页语句详解
- ORACLE中rownum与rowid区别
- 解析oracle的rownum
- 转:Oracle中的rownum不能使用大于>的问题
- 解析oracle的rownum
- Oracle ROWNUM用法和分页查询总结
- 为什么Oracle的伪列rownum不支持>,>=,=,between...and,而都用<比较
- oracle 分页(rownum的理解) 以及 树节点的查询
- (转)oracle中的rownum
- Oracle的内置分页虚拟列rownum的用法