SQL> select rowid,deptno from dept order by deptno;
ROWID DEPTNO
------------------ ----------
AAABe/AAFAAABLqAAA 10
AAABe/AAFAAABLqAAB 20
AAABe/AAFAAABLqAAC 30
AAABe/AAFAAABLqAAD 40
SQL> edit
Wrote file afiedt.buf
1* select rowid,deptno from dept order by deptno desc
SQL> /
ROWID DEPTNO
------------------ ----------
AAABe/AAFAAABLqAAD 40
AAABe/AAFAAABLqAAC 30
AAABe/AAFAAABLqAAB 20
AAABe/AAFAAABLqAAA 10
SQL> edit
Wrote file afiedt.buf
1* select rownum,deptno from dept order by deptno
SQL> /
ROWNUM DEPTNO
---------- ----------
1 10
2 20
3 30
4 40
SQL> edit
Wrote file afiedt.buf
1* select rownum,deptno from dept order by deptno desc
SQL> /
ROWNUM DEPTNO
---------- ----------
1 40
2 30
3 20
4 10
just think about ROWNUM pseudo column as a 'magic'. You can do
where rownum < n
or
where rownum = 1
but NOT
where rownum > n
or
where rownum = some number > 1
If you have to you can do something like:
select * from(
select t.*,rownum rn from t
)
where rn = 3
本文详细解释了Oracle数据库中的rowid和rownum概念。rowid作为物理地址用于定位数据的具体存储位置,而rownum则表示SQL查询结果的排序编号。通过实际例子展示了两者之间的区别及其使用场景。
993

被折叠的 条评论
为什么被折叠?



