我在 Oracle 中有一个查询。此查询的结果应该是父表的“子”表列表:
WITH tempTab AS
(SELECT owner ,
constraint_name,
table_name
FROM sys.all_constraints
WHERE owner = 'PARENT_OWNER'
AND table_name = 'PARENT_TABLE'
AND constraint_type = 'P'
)
,
acTemp AS
(SELECT DISTINCT ac.owner AS child_owner,
ac.table_name AS child_table,
ac.constraint_name
FROM sys.all_constraints ac,
tempTab tt
WHERE ac.constraint_type = 'R'
AND ac.r_constraint_name = tt.constraint_name
)
SELECT act.child_owner,
act.child_table
FROM acTemp act
它工作正常(我得到了一些行)。但是当我修改这个查询的最后几行(最后一个选择)时:
WITH tempTab AS
(SELECT owner ,
constraint_name,
table_name
FROM sys.all_constraints
WHERE owner = 'PARENT_OWNER'
AND table_name = 'PARENT_TABLE'
AND constraint_type = 'P'
)
,
acTemp AS
(SELECT DISTINCT ac.owner AS child_owner,
ac.table_name AS child_table,
ac.constraint_name
FROM sys.all_constraints ac,
tempTab tt
WHERE ac.constraint_type = 'R'
AND ac.r_constraint_name = tt.constraint_name
)
SELECT act.child_owner,
act.child_table
FROM acTemp act ,
acTemp act2,
tempTab tt
WHERE tt.owner = act2.child_owner
AND tt.table_name = act2.child_table
我没有得到任何行。为什么?在第二个查询中,我不过滤 act 表,因此结果应该与第一个查询中的相同,但事实并非如此。