名前、テーブル、およびテーブルの所有者を確認できるテーブル user_synonyms があります。この同義語がまだ有効かどうかを確認する方法はありますか。手動で試行せずに参照テーブルがまだ存在する場合は?
30908 次
3 に答える
5
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 が指摘しているように、シノニムがテーブル、ビュー、シーケンス、さらにはパッケージにある必要はありません。すべて有効です。
したがって、これらも検索するように最初のクエリを変更することをお勧めします。
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
于 2013-02-20T15:14:30.700 に答える
2
select distinct os.*
from all_objects os
,all_synonyms s
where 1 = 1
and os.object_type = 'SYNONYM'
and os.STATUS = 'INVALID'
and os.object_name = s.synonym_name
and not exists ( select unique(1)
from all_objects o1
where o1.object_name = s.TABLE_NAME
and o1.owner = s.TABLE_OWNER)
order by 2;
于 2014-10-13T05:27:14.753 に答える