我有一个表 user_synonyms,我可以在其中看到名称、表和表所有者。有没有办法查看这个同义词是否仍然有效,即。如果不手动尝试引用表仍然存在?
最佳答案
您可以通过连接 ALL_TABLES 来检查表是否存在(同义词可能不在同一架构中的表上)。
select *
from all_synonyms s
left outer join all_tables t
on s.table_owner = t.owner
and s.table_name = t.table_name
where s.owner = user
如果您想要那些表不存在的同义词,请添加条件 and t.table_name is null
。
如果要查询同义词是否为VALID查询ALL_OBJECTS .
select *
from all_synonyms s
join all_objects o
on s.owner = o.owner
and s.synonym_name = o.object_name
where o.object_type = 'SYNONYM'
and s.owner = user
and o.status <> 'VALID'
正如 a_horse_with_no_name 在评论中指出的,表、 View 、序列甚至包都不需要同义词。
因此,您可能想要更改第一个查询以查找这些:
select *
from all_synonyms s
join all_objects o
on s.table_owner = o.owner
and s.table_name = o.object_name
where s.owner = user
关于oracle - 如何检查Oracle中所有无效的同义词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14983139/