ITPub博客

首页 > 数据库 > Oracle > DBA_OBJECTS动态性能视图

DBA_OBJECTS动态性能视图

原创 Oracle 作者:中奖1000万 时间:2017-06-20 10:33:00 0 删除 编辑
DBA_OBJECTS describes all objects in the database. Its columns are the same as those in "ALL_OBJECTS".
在数据库查看该视图的字段
SQL> desc dba_objects
 Name                Null     Type
 ---------------    --------- ----------------     
 OWNER                        VARCHAR2(30)          对象所属者
 OBJECT_NAME                  VARCHAR2(128)         对象名称
 SUBOBJECT_NAME               VARCHAR2(30)          子对象名称(比如创建一个分区表,该列则会显示各分区表的名称)
 OBJECT_ID                    NUMBER                对象ID(数据库对象在数据字典中的唯一标识)
 DATA_OBJECT_ID               NUMBER                对象所对应的segment_id
 OBJECT_TYPE                  VARCHAR2(19)          对象类型
 CREATED                      DATE                  对象创建时间
 LAST_DDL_TIME                DATE                  最后一次ddl的结束时间(包含grant和revoke操作)
 TIMESTAMP                    VARCHAR2(19)          最后一次更新对象的时间
 STATUS                       VARCHAR2(7)           对象状态(VALID,INVALID, or N/A)
 TEMPORARY                    VARCHAR2(1)           表示是否是临时对象(the current session can see only data that it placed in this object itself) (Y) or not (N))
 GENERATED                    VARCHAR2(1)           表示对象名是否是系统生成的(Y,N)
 SECONDARY                    VARCHAR2(1)           表示是否是通过ODCIIndexCreate方法创建的secondary 对象(Y | N)
 NAMESPACE                    NUMBER                对象的命名空间
 EDITION_NAME                 VARCHAR2(30)          对象的命名版本
 
Related Views
DBA_OBJECTS describes all objects in the database.
USER_OBJECTS describes all objects owned by the current user. This view does not display the OWNER column.
Column                                Datatype NULL  Description
OWNER               VARCHAR2(30)       NOT NULL        Owner of the object
OBJECT_NAME         VARCHAR2(30)      NOT NULL        Name of the object
SUBOBJECT_NAME     VARCHAR2(30)                      Name of the subobject (for example, partition)
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.
OBJECT_TYPE         VARCHAR2(19)                      Type of the object (such as TABLE, INDEX)
CREATED             DATE              NOT NULL        Timestamp for the creation of the object
LAST_DDL_TIME       DATE              NOT NULL        Timestamp for the last modification of the object and dependent objects resulting from a DDL statement (including grants and revokes)
TIMESTAMP           VARCHAR2(19)                      Timestamp for the specification of the object (character data)
STATUS             VARCHAR2(7)                        Status of the object:VALID INVALID N/A
TEMPORARY           VARCHAR2(1)                        Indicates whether the object is temporary (the current session can see only data that it placed in this object itself) (Y) or not (N)
GENERATED           VARCHAR2(1)                        Indicates whether the name of this object was system-generated (Y) or not (N)
SECONDARY           VARCHAR2(1)                        Indicates whether this is a secondary object created by the ODCIIndexCreate method of the Oracle Data Cartridge (Y) or not (N)
NAMESPACE           NUMBER           NOT NULL        Namespace for the object
EDITION_NAME       VARCHAR2(30)                      Name of the edition in which the object is actual

----------------------------LOB对象涉及那些对象-------------------------------------------------------------
col OBJECT_NAME for a30
col TABLE_NAME for 30
SELECT O.OWNER,O.OBJECT_ID,  O.OBJECT_NAME, O.OBJECT_TYPE,
       L.TABLE_NAME, L.COLUMN_NAME
FROM DBA_OBJECTS O
INNER JOIN DBA_LOBS L ON L.SEGMENT_NAME=O.OBJECT_NAME AND O.OWNER =L.OWNER
ORDER BY 1;

----------------------------查看无效的对象------------------------------------------------------------------
select owner,object_name,object_type,status from dba_objects
where object_name in (select object_name from dba_objects where status = 'INVALID') order by object_name;
----------------------------对象所属用户--------------------------------------------------------------------
SQL> show user
USER is "SCOTT"
SQL> create table test101 as select 1 as id from dual;
Table created.
-----------------------------
SQL> show user
USER is "SYS"
SQL> col OBJECT_NAME for a20
SQL> select owner,object_name,object_id from dba_objects where object_name = 'TEST101';
OWNER                          OBJECT_NAME           OBJECT_ID
------------------------------ -------------------- ----------
SCOTT                          TEST101                   75349
SQL> select * from scott.test01;
select * from scott.test01
                    *
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> select owner,object_name,object_id from dba_objects where object_name = 'test101';
no rows selected
在scott用户下查询可行
SQL> select * from test101;
        ID
----------
         1
        
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
SQL> select created,status,TEMPORARY,GENERATED,EDITION_NAME,NAMESPACE from dba_objects where object_name='TEST02';
CREATED   STATUS  T G EDITION_NAME                    NAMESPACE
--------- ------- - - ------------------------------ ----------
22-MAY-17 VALID   N N                                         1
这条SQL查询出,对象TEST02的创建时间和状态,不是临时对象,不是系统生成的对象名,表空间是USERS。
SQL> select TABLE_NAME,TABLESPACE_NAME from dba_tables where TABLE_NAME='TEST02';
TABLE_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
TEST02                         USERS
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
object_id and data_object_id 区别
object_id和data_object_id同样是表示数据库对象的一个唯一标志,但是object_id表示的是逻辑id,data_object_id表示的是物理id。
    如果一些object没有物理属性的话那它就不存在data_object_id,
    例如procedure,function,package,data type,db link,mv定义,view定义,临时表,分区表定义等等这些object都是没有对应着某个segment,因此它们的data_object_id都为空。
    当表刚创建的时候它的object_id和data_object_id都是相等的,但是如果表经过move或truncate后那么data_object_id将会有变化。
SQL> create table test02 as select * from emp;
Table created.
SQL>
SQL> select object_id,data_object_id from dba_objects where object_name='TEST02';
 OBJECT_ID DATA_OBJECT_ID
---------- --------------
     75350          75350
-----------------新建的表object_id和data_object_id是一样的-------------------------
SQL> truncate table test02 ;
Table truncated.
SQL>
SQL> select object_id,data_object_id from dba_objects where object_name='TEST1'
 OBJECT_ID DATA_OBJECT_ID
---------- --------------
     75350          75351
--------------truncate table 后object_id不变,data_object_id加1---------------------
SQL>
SQL> insert into test02 select * from emp;
14 rows created.
SQL>
SQL>  create index ind_test02 on test02(empno);
Index created.
SQL>
SQL> select object_name,object_type,object_id,data_object_id from dba_objects where object_name in ('TEST02','IND_TEST02');
OBJECT_NAME          OBJECT_TYPE          OBJECT_ID DATA_OBJECT_ID
-------------------- ------------------- ---------- --------------
TEST02               TABLE                    75350          75351
IND_TEST02           INDEX                    75352          75352
SQL>
-------------------------新建的索引对象object_id和data_object_id是一样的------------------
SQL> alter table test02 move;(该操作会让索引失效)
Table altered.
SQL> commit;
Commit complete.
SQL>
SQL> select object_name,object_type,object_id,data_object_id from dba_objects where object_name in ('TEST02','IND_TEST02');
OBJECT_NAME          OBJECT_TYPE          OBJECT_ID DATA_OBJECT_ID
-------------------- ------------------- ---------- --------------
TEST02               TABLE                    75350          75351
IND_TEST02           INDEX                    75352          75352
-----------------------------表上有索引再做move table 操作,表的data_object_id没有变化
SQL>
SQL> truncate table test02;
Table truncated.
SQL>
SQL> select object_name,object_type,object_id,data_object_id from dba_objects where object_name in ('TEST02','IND_TEST02');
OBJECT_NAME          OBJECT_TYPE          OBJECT_ID DATA_OBJECT_ID
-------------------- ------------------- ---------- --------------
TEST02               TABLE                    75350          75354
IND_TEST02           INDEX                    75352          75353
--------------------------表上有索引后再truncate table ,表的data_object_id加3,索引的data_object_id加1.
结论:一个表的data_object_number大于object number,说明在表上曾经发生过truncate或者move操作。
    对于truncate操作而言,truncate后其data_object_number就是在原先的data_object_number上加1,如果表上有索引就是加2。
作用:通过查看OBJECT_ID,DATA_OBJECT_ID可以判断表是否发生过truncate或move操作。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31467250/viewspace-2140990/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2017-06-09

  • 博文量
    25
  • 访问量
    40578