对oracle伪列rownum产生机制的理解
来源:互联网 发布:阿里云栖大会苏州 编辑:程序博客网 时间:2024/06/06 16:40
rownum列数据按下面的5步生成:
1.Oracle executes your query.
2.Oracle fetches the first row and calls it row number 1.
翻译:Oracle取出第一条数据,并给字段rownum赋值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).
翻译:Oracle取出下一条数据,并给字段rownum赋递增值,比如2,3,4等。
5.Go to step 3.
为什么不能对rownum用">"?
假设存在表emp,其共col1,col2两列,多行数据,执行sql语句:select * from emp where rownum > 3.表数据如下:
列名 col1 col2 col3 rownum
列值 001 a b
002 a b
003 a b
004 a b
005 a b
...
...
步骤1中,oracle按非rownum相关的条件查询出所有记录
列名 col1 col2 col3 rownum
列值 001 a b
002 a b
003 a b
004 a b
005 a b
...
...
步骤2中,oracle取出第一条数据,并给其rownum列赋值1,如下
列名 col1 col2 col3 rownum
列值 001 a b 1
002 a b
003 a b
004 a b
005 a b
步骤3中,对rownum已有值的列:001 a b 1进行判断,判断条件是rownum > 3,结果为no,该行丢弃。
列名 col1 col2 col3 rownum
列值 002 a b
003 a b
004 a b
005 a b
...
...
步骤4中,对行002 a b的rownum赋值为1,因为第三步已经丢弃了行001 a b,如果没有丢弃,应该对002 a b的rownum赋值为2
列名 col1 col2 col3 rownum
列值 002 a b 1
003 a b
004 a b
005 a b
...
...
步骤5又跳入步骤3,仍进行rownum > 3的判断,仍然丢弃数据,到第四步新行的rownum仍然赋值为1,如此循环下去,select * from emp where rownum > 3查询结果为空。
- 对oracle伪列rownum产生机制的理解
- Oracle rownum 伪列
- oracle伪列rownum
- Oracle伪列rownum
- Oracle伪列rownum
- Oracle-伪列(rownum)
- oracle中的rownum伪列的使用
- MySQL实现Oracle的rownum伪列
- Oracle的数据伪列(ROWNUM)
- oracle中的rownum伪列的使用
- oracle中的伪列rownum
- Oracle Rownum 伪列详解
- oracle中的伪列rownum
- Oracle Rownum 伪列详解
- Oracle Rownum 伪列详解
- Oracle中的伪列ROWNUM
- Oracle Rownum 伪列详解
- oracle中的伪列 rownum
- 人生就是这样
- 人生就是这样
- 日语输入法使用小结
- 微软、谷歌、百度等公司经典面试100题
- Mac终端显示隐藏
- 对oracle伪列rownum产生机制的理解
- 域渗透
- spring和JDBC
- Vmware View 4.5 体验
- Const,Const函数,Const变量,函数后面的Const (zz)
- win7下nginx+php安装
- Controller override and request rewrite in Magento
- Android 全局数据的应用
- What does backend type static mean in Magento?