在user_objects等视图里面有两个比较容易搞混的字段object_id和data_object_id
这两个字段基本上有什么大的区别呢?
object_id其实是对每个数据库中数据对象的唯一标识
data_object_id用的相比来说会少一些,主要是和seg$对应,用来表示object的物理存储段的实际位置.
只有表,索引,undo这些有实际物理存储位置的对象才有data_object_id,而像一些函数,存储过程,以及view等等是没有data_object_id的,也就是说仅有object_id
来看个实验就一目了然了:
C:\>sqlplus /nolog
SQL*Plus: Release 10.2.0.3.0 - Production on 星期四 2月 14 11:03:41 2008
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
SQL> conn / as sysdba;
已连接。
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
SQL> create table test as select * from dual;
表已创建。
SQL> select object_id,data_object_id from user_objects where object_name='TEST';
OBJECT_ID DATA_OBJECT_ID
---------- --------------
56278 56278
SQL> create view view_test as select * from test;
视图已创建。
SQL> select object_id,data_object_id from user_objects where object_name='VIEW_TEST';
OBJECT_ID DATA_OBJECT_ID
---------- --------------
56279
这里可以看到具有物理存储段的对象table是存在data_object_id,而view就没有.
根据上面的实验我们可以看到,object_id和data_object_id的一些微妙的关系,大部分的对象在一般情况下,这两个值是相等的.
当创建一个新的对象的时候object_id和data_object_id应该分别取
max(select max(object_id) from dba_objects)+1,
max(select max(hwmincr) from seg$)+1
但是在个别情况下两个值会不同,比如我们
进行truncate,move等操作.
看一下下面的实验,就利用我们刚刚创建好的test表来试图说明这个问题:
SQL> select object_id,data_object_id from user_objects where object_name='TEST';
OBJECT_ID DATA_OBJECT_ID
---------- --------------
56278 56278
SQL> truncate table test;
表被截断。(注意这个有内容的情况下才会改变data_object_id)
SQL> select object_id,data_object_id from user_objects where object_name='TEST';
OBJECT_ID DATA_OBJECT_ID
---------- --------------
56278 56279
转自:http://blog.itpub.net/12361284/viewspace-170223/