For each row in the database, the ROWID pseudocolumn returns a row’s address. Oracle9i rowid values contain information necessary to locate a row: n The data object number of the object n Which data block in the datafile n Which row in the data block (first row is 0) n Which datafile (first file is 1). The file number is relative to the tablespace. Usually, a rowid value uniquely identifies a row in the database. However, rows in different tables that are stored together in the same cluster can have the same rowid.
SQL> select rowid ,id from zhj;ROWID ID ------------------ ---------- AAABwpAACAAAN/SAAA 1 AAABwpAACAAAN/SAAB 2 AAABwpAACAAAN/SAAC 3 AAABwpAACAAAN/SAAD 4 AAABwpAACAAAN/SAAE 5 AAABwpAACAAAN/SAAF 6 AAABwpAACAAAN/SAAG 7 AAABwpAACAAAN/SAAH 8 AAABwpAACAAAN/SAAI 9 AAABwpAACAAAN/SAAJ 10已选择10行。SQL> select * from zhj where rowid='AAABwpAACAAAN/SAAA'; ID NAME TYPE ---------- -------------------- ----- 1 zhang aaa01
这样作我看没问题
ROWID是记录物理地址,所以当记录的地址改变,它就改变.
但是在什么情况下,记录的地址会改变呢?当记录被Update?
我个人认为,记录的地址不会被改变(即使发生ROW migration )
请在结贴是把它放入FAQ
就是说数据已经写入数据库,他会不会像整理磁盘碎片那样给你搬到了别的地方?那样rowid不就改变了吗?
Oracle9i rowid values contain information necessary to locate a row:
n The data object number of the object
n Which data block in the datafile
n Which row in the data block (first row is 0)
n Which datafile (first file is 1). The file number is relative to the tablespace.
Usually, a rowid value uniquely identifies a row in the database. However, rows in
different tables that are stored together in the same cluster can have the same rowid.
------------------ ----------
AAABwpAACAAAN/SAAA 1
AAABwpAACAAAN/SAAB 2
AAABwpAACAAAN/SAAC 3
AAABwpAACAAAN/SAAD 4
AAABwpAACAAAN/SAAE 5
AAABwpAACAAAN/SAAF 6
AAABwpAACAAAN/SAAG 7
AAABwpAACAAAN/SAAH 8
AAABwpAACAAAN/SAAI 9
AAABwpAACAAAN/SAAJ 10已选择10行。SQL> select * from zhj where rowid='AAABwpAACAAAN/SAAA'; ID NAME TYPE
---------- -------------------- -----
1 zhang aaa01
rowid不是操作系统中的地址,而是数据库中的书摘:
数据库中的每一行都有地址,可用rowid来检索,rowid的格式如下block.row.file
......
Rows in different tables that are stored together in the same cluster can have the same rowid
6个表示段号,3个表示数据文件号,6个表示块号,3个表示行号
其实可以用自增一的字段实现,但oracle不想sql server可以自动建立,因此实现起来比较麻烦,正好oracle提供rowid,觉得挺方便!