rownum 详解

ROWNUM是一个序列,是oracle数据库从数据文件或缓冲区中读取数据的顺序。它取得第一条记录则rownum值为1,第二条为2,依次类推。
如果 你用>,>=,=,between…and这些条件,因为从缓冲区或数据文件中得到的第一条记录的rownum为1,则被删除,接着取下 条,
可是它的rownum还是1,又被删除,依次类推,便没有了数据。
rownum 的原理

题目:
1.drop table t;
create table t as select rownum rn from dba_objects where rownum <= 100;
2. select * from t where rownum =1 ;
select * from t where rownum >=1 ;
select * from t where rownum >=5 ;
select * from t where rownum =5 ;
select * from t where rownum <=5 ;
rownum是在执行期间生成的数据,没有1,怎么可能有2
rownum在oralce内编写方式
select * from t where rownum =1 ;
begin
rownum = 1 
For x in ( select * from t )   --rownum=1,可以进入循环
Loop 
  if ( rownum = 1 ) 
  then 
     output date 
     rownum = rownum+1 
  end if; 
End loop;
end;
select * from t where rownum >=5 ;  ----因为rownum=1.所以直接退出循环,没有输出
rownum = 1 
For x in ( select * from t ) 
Loop 
  if ( rownum >= 5 ) 
  then 
     output date 
     rownum = rownum+1 
  end if; 
End loop;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21861353/viewspace-757908/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/21861353/viewspace-757908/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值