如何在 oracle 中找到外部约束键的父 table?

How can I find the parent table of a foreign constraint key in oracle?

如何在 oracle 的 table 键上找到外部约束的父 table(s)?我需要创建一个下拉列表,其中包含可以为我正在查看的此列选择的所有值,并且需要知道父项以便我可以查找其同级值。

您可以从 all_constraints (or user_constraints or dba_constraints, of course). Unfortunately, you can only retrieve the name of the constraint a foreign key refers to, so you'll have to use a sub query or a self join 查询此信息以检索引用 table:

SELECT r.table_name
FROM   user_constraints t
JOIN   user_constraints r ON t.r_constraint_name = r.constraint_name
WHERE  t.constraint_type = 'R' AND t.table_name = 'SOME_TABLE'

您可以使用以下查询获取父级 table。

select * from all_constraints
where constraint_name in (select r_constraint_name from all_constraints
where table_name in 'TAB_NAME');