ROWID与ROWNUM的简介与对比(二)

2014-11-24 17:09:57 · 作者: · 浏览: 1
AAFT7AAEAAAAIFAAB 1 2 20 RESEARCH DALLAS
AAAFT7AAEAAAAIFAAA 0 1 10 ACCOUNTING NEW YORK

关于不同的排序结果使用ROWNUM,ROWNUM显示会不会变化? 实验结果是不会改变的

BYS@ bys3>select rownum,dept.* from dept;

ROWNUM DEPTNO DNAME LOC
---------- ---------- -------------- -------------
1 10 ACCOUNTING NEW YORK
2 20 RESEARCH DALLAS
3 40 OPERATIONS BOSTON
4 99 chedan bj
BYS@ bys3>select rownum,dept.* from dept order by loc;
ROWNUM DEPTNO DNAME LOC
---------- ---------- -------------- -------------
3 40 OPERATIONS BOSTON
2 20 RESEARCH DALLAS
1 10 ACCOUNTING NEW YORK
4 99 chedan bj

查表中最后一行记录的方法:

BYS@ bys3>select * from dept where rowid in(select max(rowid) from dept);
DEPTNO DNAME LOC
---------- -------------- -------------
40 OPERATIONS BOSTON
BYS@ bys3>select * from dept where rownum<=(select count(*) from dept) minus select * from dept where rownum<=(select count(*)-1 from dept);
DEPTNO DNAME LOC
---------- -------------- -------------
40 OPERATIONS BOSTON