做培訓的時候認爲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的內部原理相關。