首页 > 解决方案 > 如何知道数据库中某处是否使用了 db-link

问题描述

我想知道是否存在一个 Oracle 命令来了解 DB-LINK(名称:myBDLink)是否在数据库中的某个位置使用以及如何显示对象(视图、物化视图、过程、函数......)用它。

你能帮我吗?

谢谢你的帮助

标签: oracleviewdblink

解决方案


好吧,您可以尝试查询各种系统视图,看看它们中的任何一个是否包含您要查找的字符串。当您想检查整个数据库时,您可能会以特权用户身份连接并检查dba_视图;否则,all_或者user_会这样做。

例如,检查过程、函数、包……:

select owner, name, type, line
from dba_source
where owner not in ('SYS', 'SYSTEM')
  and lower(text) like '%mydblink%';

要检查视图,您需要一个函数来搜索其LONG数据类型列(因为您不能直接在 SQL 中使用它):

create or replace function f_long(par_view in varchar2, par_String in varchar2) 
  return varchar2 
is
  l_text varchar2(32000);
begin
  select text 
    into l_text
    from dba_views 
    where owner not in ('SYS', 'SYSTEM')
      and view_name = par_view;
    
  return case when instr(lower(l_text), lower(par_string)) > 0 then 1
              else 0 
         end;              
end;
/

接着

select owner, view_name 
from dba_views
where f_long(view_name, 'mydblink') = 1;

我排除了SYSSYSTEM因为它们不应该包含任何用户的东西。也许您想排除更多用户。


要查看更多(重新)资源,请查询字典,例如

select table_name, comments
from dictionary;

TABLE_NAME                     COMMENTS
------------------------------ --------------------------------------------------
USER_CONS_COLUMNS              Information about accessible columns in constraint
                                definitions

ALL_CONS_COLUMNS               Information about accessible columns in constraint
                                definitions

DBA_CONS_COLUMNS               Information about accessible columns in constraint
                                definitions
<snip>

推荐阅读