views:

50

answers:

2

I'm trying to get CONSTRAINTS from user_objects table like this:

 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
; 

But..... USER_OBJECTS has only these types FUNCTION
INDEX, PACKAGE, PACKAGE BODY, PROCEDURE, SEQUENCE, TABLE, TRIGGER, VIEW because select distinct object_type from user_objects; returned them. So this query is not giving my the constraints at all.

Is there a way to get all constraints from Oracle? Which Oracle view should I use?

+4  A: 
   select * from user_constraints
Michael Pakhantsov
+1  A: 

Constraints aren't objects. So they're in a different view, namely USER_CONSTRAINTS. For foreign constraints, you'll need a self join:

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

Some details can also be found in USER_CONS_COLUMNS.

Codo
found the solution by using a union select constrains || '|' || c.constraint_name OBJ from user_constraints c inner join all_constraints cc on c.r_constraint_name = cc.constraint_name order by OBJ/
blaap
select CASE object_type ....bladiebladiebla.... ELSE object_type END||'|'|| object_name OBJfrom 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 in ('PACKAGE BODY')
blaap