做培训的时候认为rowid的前六位存储的是object_id,其实是错误的它代表的应该是data_object_id.
关于rowid请看:http://blog.csdn.net/zhou689689/article/details/8775251
官方解释:
OBJECT_ID | NUMBER | NOT NULL | Dictionary object number of the object |
DATA_OBJECT_ID | NUMBER | Dictionary object number of the segment that contains the object | |
Note: OBJECT_ID and DATA_OBJECT_ID display data dictionary metadata. Do not confuse these numbers with the unique 16-byte object identifier (object ID) that Oracle Database assigns to row objects in object tables in the system. |
测试:
SQL> create table test_object_id(id int,name varchar2(20));
Table created
Executed in 0.016 seconds
SQL> select object_id,data_object_id from user_objects where object_name=upper('test_object_id'); --初始两个值是一致的
OBJECT_ID DATA_OBJECT_ID
---------- --------------
56943 56943
Executed in 0.047 seconds
SQL> insert into test_object_id values(1,'kk'); --插入数据
1 row inserted
Executed in 0.032 seconds
SQL> commit;
Commit complete
Executed in 0 seconds
SQL> select dbms_rowid.rowid_object(rowid) object_id from test_object_id where rownum=1; --查询数据的rowid中记录的object_id
OBJECT_ID
----------
56943
Executed in 0.031 seconds
SQL> truncate table test_object_id; --truncate一下
Table truncated
Executed in 0.015 seconds
SQL> select object_id,data_object_id from user_objects where object_name=upper('test_object_id'); --发现DATA_OBJECT_ID值变了
OBJECT_ID DATA_OBJECT_ID
---------- --------------
56943 56944
Executed in 0.063 seconds
SQL> insert into test_object_id values(1,'kk');
1 row inserted
Executed in 0 seconds
SQL> commit;
Commit complete
Executed in 0.016 seconds
SQL> select dbms_rowid.rowid_object(rowid) object_id from test_object_id where rownum=1; --rowid中记录的object_id
OBJECT_ID
----------
56944
Executed in 0.062 seconds
总结:rowid中记录的是对象对应的段的id,当进行过truncate操作时,对象对应的段id会改变。而rowid是唯一指定行存储的,所以里面描述的是段的编号而不是对象编号。
对象编号(object_id)在对象的生命周期内是不会改变的。
具体oracle为什么这样弄,可能是和truncate的内部原理相关。