码迷,mamicode.com
首页 > 数据库 > 详细

oracle: Rownum原理

时间:2016-09-26 16:19:15      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

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,所以永远是false,rownum不改变,所有的行都被抛弃,所以没有结果。

where rownum = n(n>1)

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

oracle: Rownum原理

标签:

原文地址:http://www.cnblogs.com/mpxBlog/p/5909288.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!