哪个 Oracle 视图包含所有约束?

发布于 2024-09-24 10:45:56 字数 1117 浏览 9 评论 0原文

我试图从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞旧 2024-10-01 10:45:56
   select * from user_constraints
   select * from user_constraints
×纯※雪 2024-10-01 10:45:56

约束不是对象。所以他们处于不同的视图,即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 中找到。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文