[20141029]10g和11G视图DBA_CONSTRAINTS

[20141029]10g和11G视图DBA_CONSTRAINTS.txt

--上午同事讲一下表从10g导入11g时,一些约束没有导入,感觉不可能出现这种情况,我在10g下查看一些约束的状态是是disabled,但是
--type显示的是问号(在toad下).想起来我以前遇到的问题,

--[20140131]toad看constraints的问题.txt

http://blog.itpub.net/267265/viewspace-1076597/

--很容易明白这些表是没有主键,不过在11g下查看视图DBA_CONSTRAINTS确实没有这些约束,查看视图定义才发现11g下DBA_CONSTRAINTS的
--定义发生了变化:

SYS@test> select text from dba_views where view_name='DBA_CONSTRAINTS';
TEXT
-------------------------------------------------------------------------------
select ou.name, oc.name,
       decode(c.type#, 1, 'C', 2, 'P', 3, 'U',
              4, 'R', 5, 'V', 6, 'O', 7,'C', 8, 'H', 9, 'F',
              10, 'F', 11, 'F', 13, 'F', '?'),
       o.name, c.condition, ru.name, rc.name,
       decode(c.type#, 4,
              decode(c.refact, 1, 'CASCADE', 2, 'SET NULL', 'NO ACTION'),
              NULL),
       decode(c.type#, 5, 'ENABLED',
              decode(c.enabled, NULL, 'DISABLED', 'ENABLED')),
       decode(bitand(c.defer, 1), 1, 'DEFERRABLE', 'NOT DEFERRABLE'),
       decode(bitand(c.defer, 2), 2, 'DEFERRED', 'IMMEDIATE'),
       decode(bitand(c.defer, 4), 4, 'VALIDATED', 'NOT VALIDATED'),
       decode(bitand(c.defer, 8), 8, 'GENERATED NAME', 'USER NAME'),
       decode(bitand(c.defer,16),16, 'BAD', null),
       decode(bitand(c.defer,32),32, 'RELY', null),
       c.mtime,
       decode(c.type#, 2, ui.name, 3, ui.name, null),
       decode(c.type#, 2, oi.name, 3, oi.name, null),
       decode(bitand(c.defer, 256), 256,
              decode(c.type#, 4,
                     case when (bitand(c.defer, 128) = 128
                                or o.status in (3, 5)
                                or ro.status in (3, 5)) then 'INVALID'
                          else null end,
                     case when (bitand(c.defer, 128) = 128
                                or o.status in (3, 5)) then 'INVALID'
                          else null end
                    ),
              null),
       decode(bitand(c.defer, 256), 256, 'DEPEND ON VIEW', null)
from sys.con$ oc, sys.con$ rc, sys."_BASE_USER" ou, sys."_BASE_USER" ru,
     sys."_CURRENT_EDITION_OBJ" ro, sys."_CURRENT_EDITION_OBJ" o, sys.cdef$ c,
     sys.obj$ oi, sys.user$ ui
where oc.owner# = ou.user#
  and oc.con# = c.con#
  and c.obj# = o.obj#
  and c.type# != 8        /* don't include hash expressions */
  and (c.type# 17)    /* don't include supplog cons   */
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  and (c.type# != 12)                   /* don't include log group cons */
  and c.rcon# = rc.con#(+)
  and c.enabled = oi.obj#(+)
  and oi.owner# = ui.user#(+)
  and rc.owner# = ru.user#(+)
  and c.robj# = ro.obj#(+)

--注意~的部分.(c.type# 17)不显示.如果查看10g的定义没有这些部分.

$ grep -i 'cdef\$' * | grep -i 'create table cdef'
dcore.bsq:create table cdef$                            /* constraint definition table */

create index i_cobj# on cluster c_cobj#
/
REM NOTE
REM Logminer/Streams uses contents of this table.
REM Please do not reuse any flags without verifying the impact of your
REM changes on inter-op.
create table cdef$                            /* constraint definition table */
( con#          number not null,                        /* constraint number */
  obj#          number not null,         /* object number of base table/view */
  cols          number,                   /* number of columns in constraint */
  type#         number not null,                         /* constraint type: */
                 /* Note: If new types are added then please ensure that the */
                 /* {....}_CONSTRAINTS family of views reflect the new type. */
                            /* 1 = table check, 2 = primary key, 3 = unique, */
                             /* 4 = referential, 5 = view with CHECK OPTION, */
                                                 /* 6 = view READ ONLY check */
               /* 7 - table check constraint associated with column NOT NULL */
                                   /* 8 - hash expressions for hash clusters */
                                         /* 9 - Scoped REF column constraint */
                                    /* 10 - REF column WITH ROWID constraint */
                                  /* 11 - REF/ADT column with NOT NULL const */
                                 /* 12 - Log Groups for supplemental logging */
                                 /* 13 - Allow PKref vals Storage in REF col */
                                    /* 14 - Primary key supplemental logging */
                                     /* 15 - Unique key supplemental logging */
                                    /* 16 - Foreign key supplemental logging */
                                     /* 17 - All column supplemental logging */
  robj#         number,                 /* object number of referenced table */
  rcon#         number,           /* constraint number of referenced columns */
  rrules        varchar2(3),         /* future: use this columns for pendant */
  match#        number,                /* referential constraint match type: */
                                                 /* null = FULL, 1 = PARTIAL */
        /* this column can also store information for other constraint types */
  refact        number,                               /* referential action: */
              /* null = RESTRICT, 1 = CASCADE, 2 = SET NULL, 3 = SET DEFAULT */
  enabled        number,          /* is constraint enabled? NULL if disabled */
  condlength    number,                 /* table check condition text length */
  condition     long,                          /* table check condition text */
  intcols       number,          /* number of internal columns in constraint */
  mtime         date,      /* date this constraint was last enabled-disabled */
  defer         number,                     /* 0x01 constraint is deferrable */
                                              /* 0x02 constraint is deferred */
                                /* 0x04 constraint has been system validated */
                                 /* 0x08 constraint name is system generated */
                       /* 0x10 constraint is BAD, depends on current century */
                           /* 0x20, optimizer should RELY on this constraint */
                                             /* 0x40 Log Group ALWAYS option */
                                /* 0x80 (view related) constraint is invalid */
                                       /* 0x100 constraint depends on a view */
                            /* 0x200 constraint is a partitioning constraint */
  spare1        number,                      /* sql version flag: see kpul.h */
  spare2        number,            /* create/last modify constraint SCN wrap */
  spare3        number,            /* create/last modify constraint SCN base */
  spare4        varchar2(1000),
  pare5        varchar2(1000),
  spare6        date
)
cluster c_cobj#(obj#)
/

--做一个简单的测试:
SCOTT@test> @ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.3.0     Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

create table ttx
(    a number(1) not null,
     b number(1),
     SUPPLEMENTAL LOG DATA (ALL) COLUMNS
);

SCOTT@test> select dbms_metadata.get_ddl('TABLE', 'TTX') from dual ;
DBMS_METADATA.GET_DDL('TABLE','TTX')
-----------------------------------------------------------------------

  CREATE TABLE "SCOTT"."TTX"
   (    "A" NUMBER(1,0) NOT NULL ENABLE,
        "B" NUMBER(1,0),
         SUPPLEMENTAL LOG DATA (ALL) COLUMNS
   ) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
  TABLESPACE "USERS" ;

SCOTT@test> select owner,CONSTRAINT_NAME from DBA_CONSTRAINTS where owner=user and table_name='TTX';
OWNER  CONSTRAINT_NAME
------ ------------------------------
SCOTT  SYS_C0042410

--可以发现仅仅有1个约束.

SELECT CON#,
       OBJ#,
       COLS,
       TYPE#,
       ROBJ#,
       RCON#,
       RRULES,
       MATCH#,
       REFACT,
       ENABLED,
       CONDLENGTH,
       CONDITION
  FROM sys.cdef$
WHERE obj# IN (SELECT object_id
                  FROM dba_objects
                 WHERE object_name = 'TTX' AND owner = USER);

CON#       OBJ#       COLS      TYPE#      ROBJ#      RCON# RRU     MATCH#     REFACT    ENABLED CONDLENGTH CONDITION
----- ---------- ---------- ---------- ---------- ---------- --- ---------- ---------- ---------- ---------- -----------------
42410     292348          1          7                                                          1         15 "A" IS NOT NULL
42411     292348          0         17

-- 可以发现实际上有2个的,type#=17的在DBA_CONSTRAINTS视图就不显示了.

SCOTT@test> alter table ttx drop supplemental log data (all) columns;
Table altered.

SCOTT@test> select dbms_metadata.get_ddl('TABLE', 'TTX') from dual ;
DBMS_METADATA.GET_DDL('TABLE','TTX')
----------------------------------------------------------------------------

  CREATE TABLE "SCOTT"."TTX"
   (    "A" NUMBER(1,0) NOT NULL ENABLE,
        "B" NUMBER(1,0)
   ) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
  TABLESPACE "USERS" ;

SELECT CON#,
       OBJ#,
       COLS,
       TYPE#,
       ROBJ#,
       RCON#,
       RRULES,
       MATCH#,
       REFACT,
       ENABLED,
       CONDLENGTH,
       CONDITION
  FROM sys.cdef$
WHERE obj# IN (SELECT object_id
                  FROM dba_objects
                 WHERE object_name = 'TTX' AND owner = USER);

CON#       OBJ#       COLS      TYPE#      ROBJ#      RCON# RRU     MATCH#     REFACT    ENABLED CONDLENGTH CONDITION
----- ---------- ---------- ---------- ---------- ---------- --- ---------- ---------- ---------- ---------- ----------------------------------------
42410     292348          1          7                                                          1         15 "A" IS NOT NULL

时间: 2024-10-23 08:47:04

[20141029]10g和11G视图DBA_CONSTRAINTS的相关文章

关于create database语句在10g,11g中的不同

最近抽空练习了下手工建库,在10g的时候基本都在20分钟搞定,在11g中其实还可以更快,因为10g中需要配置的admin目录,需要创建bdump,udump之类的目录等等,在11g都被adr给默认替代了,只要提供了$ORACLE_BASE,就会默认在$ORACLE_BASE下生成对应的目录结构. 其它步骤完全可以按照10g的脚本来使用,没有任何问题,但是如果反过来,在11g里使用的一些语句在10g中可能会有一些问题,这一点也是在今天的测试中发现的一个小细节. 首先我在11g的库中创建了一个数据库

oracle 10g和11g版本数据库重建awr的例子

由于某种原因,比如数据异常断电,导致awr数据严重不一致,awr部分表损坏等情况,需要重建awr,可以参考如下步骤进行重建,本文主要针对目前主流的10g和11g版本数据库,12c未进行测试 停止awr自动收集信息 方法1:参数调整 sqlplus /nolog connect / as sysdba create pfile='/tmp/pfile.xifenfei' from spfile; alter system set shared_pool_size = 200m scope = sp

【sessions】Oracle中sessions和processes的大小关系(10g和11g不同)

[sessions]Oracle中sessions和processes的大小关系(10g和11g不同) 1  BLOG文档结构图 BLOG_Oracle_lhr_[sessions]Oracle中sessions和processes的大小关系(10g和11g不同).pdf 2  前言部分 2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识,~O(∩_∩)O~: ① sessions和processes的大小设置,10g和11g不同(重点

10g和11g中的一些差别

最近有时候看官方文档,感觉11g里面已经有了很多的变化,无论是使用还是安装上的细节上,11g似乎总是能够带给我更多的惊喜.而从以往的使用情况中感觉10g已经足够了,但是越多的使用11g,逐渐的改变了自己的固有思维,很多原来不好,不方便的操作习惯都得到了很大的改善.我就从10g和11g共有的一些细节之处来一窥两个版本中的差别.细节还是太多,我就扒出小部门. 大体会从下面几个部分进行对比和说明,有一些部分已经写了一些文章了,所以突然回顾一下会发现原来这些看似清汤寡水的文章里面还是有值得推敲的东西.

10g升级至11g需要考虑的参数优化

10g升级至11g除了需要做一个详尽的计划, 需要采集10g系统的负载情况,做一个整体的把握,在升级之后,再做负载分析. 保证不会出现大的问题,sql的执行计划不会有大的变动. 参数优化方面,需要考虑下面3个方面. à对于 deprecated Parameter in 11G The following parameters are deprecated from 11G onwards, need suggestion for these parameters. Name Note    

使用带dblink方式的datapump迁移Oracle 10g到11g

      对于从Oracle 10g下迁移数据库到Oracle 11g,除了使用RMAN方式之外,我们可以使用带dblink的datapump方式来实现基于逻辑上的迁移.其步骤也相对简单,而且不会产生中间过程生成的dump文件.本文即针对如何使用该方法给出了示例,供大家参考.   1.确保源数据库和目标数据库处于可用状态 --环境描述 --源库: mftst Oracle 10.2.0.3 + Enterprise Linux Enterprise Linux Server release 5

从Oracle 10g到11g,到底该升不该升?

    话题 Topic Oracle 10gR2目前运行比较平稳,从你的角度来说说,是否有升级的必要性?可从正反两方面来讨论,先抛出论点,再阐述论据.(本期话题贡献人:杨志洪)    正方:升  彭小波:在今年的7月份,我们10多套生产库从10g升级到了11g,高版本是下兼容的,10g在市场运行了这么多年,是相当稳定了.但是11g中改进了很多优化器的算法,也增加很多新特性.不管是从优化,还是管理上,对DBA来说都是一大福音.在升级的过程,我们也遇到一点小问题.   1.在10g升级到11g时,

10g升级至11g exp的问题解决

昨天升级数据库,从10.2.0.5.0升级到11.2.0.2.0. 按照预定的步骤很快就操作完了.升级完成后,开始跑一些应用和Job.有一个Job开始报错,Job是一个自动的同步job,中会有exp的动作,而且里面用到了consistent=y的选项,这样exp就大体如下: exp xxxx/xxxx file=xxx.dmp tables=xxxx consistent=y 报错如下: Export: Release 11.2.0.2.0 - Production on Mon Sep 23

Oracle 10g 到11g的数据迁移 导入导出 顺序步骤 expdp/impdp

原库版本:Oracle 10.2.0.4.0 目标库版本:Oracle 11.2.0.1.0 使用expdp导出原库数据: expdp system/xxxxxx schemas=test1201 directory=easbak dumpfile=test1201.dmp logfile=zytest1201.log; impdp前准备: 1:确保目标数据库和原库字符集一致 2:创建好所需表空间,可以在原库里查询test1201这个用户使用了哪些表空间查询语句如下: select distin