Oracle rownum原理

来源:互联网 发布:大英博物馆知乎 编辑:程序博客网 时间:2024/06/11 22:27

Rownum原理:

1 Oracle executes your query.

执行查询操作

2 Oracle fetches the first row and calls it row number 1.

将第一行的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.

将得到的行的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).

oracle获取下一行,然后将rownum增1

5 Go to step 3.

返回第3

从这个原理可以知道,select rownum,name from emp where rownum>5;不返回行,因为首先执行查询select name from emp,将第1行的rownum标为1,然后看where条件,为false,则抛弃行,执行第2行,还是rownum标为1,看where条件还为false,所以永远是falserownum不改变,所有的行都被抛弃,所以没有结果。

where rownum = n(n>1)

where rownum > n 都不可用,也就是上面的原因

0 0
原创粉丝点击