【问题标题】:Which Oracle view contains all constraints together?哪个 Oracle 视图包含所有约束?
【发布时间】:2011-04-16 17:10:03
【问题描述】:

我正在尝试从 user_objects 表中获取 CONSTRAINTS,如下所示:

 select CASE object_type
      WHEN 'DATABASE LINK' then 'dblinks'
      WHEN 'FUNCTION' then 'functions'
      WHEN 'INDEX' then 'indexes'
      WHEN 'PACKAGE' then 'packages'
      WHEN 'PROCEDURE' then 'procedures'
      WHEN 'SEQUENCE' then 'sequences'
      WHEN 'TABLE' then 'tables'
      WHEN 'TRIGGER' then 'triggers'
      WHEN 'VIEW' then 'views'
      WHEN 'SYNONYM' then 'synonyms'
      WHEN 'GRANT' then 'grants'
      WHEN 'CONSTRAINT' then 'constraints'
      ELSE object_type
      END||'|'||
      CASE object_type
      WHEN 'DATABASE LINK' then 'DB_LINK'
      ELSE object_type
      END||'|'||object_name
from user_objects
where object_name not like 'BIN$%'
and object_type not like '%PARTITION'
and object_type not in ('PACKAGE BODY')
order by object_type
; 

select distinct object_type
from user_objects
; 

但是..... USER_OBJECTS 只有这些类型 FUNCTION
INDEX、PACKAGE、PACKAGE BODY、PROCEDURE、SEQUENCE、TABLE、TRIGGER、VIEW 因为从 user_objects 中选择不同的 object_type;退还了他们。所以这个查询根本没有给我任何约束。

有没有办法从 Oracle 获取所有约束?我应该使用哪个 Oracle 视图?

【问题讨论】:

    标签: oracle constraints ddl schemaexport dbms-metadata


    【解决方案1】:

    约束不是对象。所以他们有不同的看法,即USER_CONSTRAINTS。对于外部约束,您需要一个自联接:

    select * from user_constraints c
    left join user_constraints r on r.owner = c.r_owner and r.constraint_name = c.r_constraint_name
    where c.constraint_type = 'R';
    

    一些细节也可以在USER_CONS_COLUMNS找到。

    【讨论】:

    • 通过联合选择约束找到了解决方案 || '|' || c.constraint_name OBJ from user_constraints c inner join all_constraints cc on c.r_constraint_name = cc.constraint_name order by OBJ/
    • 选择 CASE object_type ....bladiebladiebla.... ELSE object_type END||'|'|| object_name OBJ from user_objects where ... WHEN 'DATABASE LINK' then 'DB_LINK' ELSE object_type END||'|'||object_name from user_objects where object_name not like 'BIN$%' and object_type not like '%PARTITION' and object_type not在('包体')
    【解决方案2】:
       select * from user_constraints
    

    【讨论】:

      猜你喜欢
      • 2020-10-06
      • 2018-03-04
      • 2022-01-26
      • 2010-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多