2010-09-24 6 views
2

Je suis en train de se CONTRAINTES de user_objects table comme ceci:Quelle vue Oracle contient toutes les contraintes ensemble?

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 
; 

Mais ..... user_objects a seulement ces types FONCTION
INDEX, EMBALLAGE, CORPS DE L'EMBALLAGE, PROCEDURE, SEQUENCE, TABLE, TRIGGER , VIEW parce que select object_type distinct de user_objects; les a renvoyés. Donc, cette requête ne donne pas mes contraintes du tout.

Existe-t-il un moyen d'obtenir toutes les contraintes d'Oracle? Quelle vue Oracle devrais-je utiliser?

Répondre

5
select * from user_constraints 
3

Les contraintes ne sont pas des objets. Donc, ils sont dans une vue différente, à savoir USER_CONSTRAINTS. Pour des contraintes étrangères, vous aurez besoin d'une jointure réflexive:

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'; 

Certains détails peuvent être trouvés dans USER_CONS_COLUMNS.

+0

trouvé la solution en utilisant une union select contraintes || '|' || c.constraint_name OBJ de user_constraints c jointure interne all_constraints cc sur c.r_constraint_name = cc.constraint_name trié par OBJ/ – Ronaldus

+0

select CASE type_objet .... bladiebladiebla .... ELSE type_objet FIN || '|' || object_name OBJ de user_objects où ... QUAND 'DATABASE LINK' puis 'db_link' AUTRE object_type FIN || '|' || OBJECT_NAME de user_objects où nom_objet pas comme 'BIN $%' et object_type pas comme '% PARTITION' et object_type non dans ('PACKAGE BODY') – Ronaldus

Questions connexes