rowid理解误区解释

做培训的时候认为rowid的前六位存储的是object_id,其实是错误的它代表的应该是data_object_id.

关于rowid请看:http://blog.csdn.net/zhou689689/article/details/8775251

官方解释:

OBJECT_IDNUMBERNOT NULLDictionary object number of the object
DATA_OBJECT_IDNUMBER 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的内部原理相关。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值