哪个 Oracle 视图包含所有约束?
我试图从 user_objects 表中获取约束,如下所示:
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 视图?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
约束不是对象。所以他们处于不同的视图,即
USER_CONSTRAINTS
。对于外部约束,您需要自连接:一些详细信息也可以在
USER_CONS_COLUMNS
中找到。Constraints aren't objects. So they're in a different view, namely
USER_CONSTRAINTS
. For foreign constraints, you'll need a self join:Some details can also be found in
USER_CONS_COLUMNS
.