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/