-- 查询已存在的db_link
select * from dba_db_links;
select * from ALL_DB_LINKS;
select owner,object_name from dba_objects where object_type='DATABASE LINK';
--创建db_link(加上publik为全局的db_link)
create /*public*/ database link ESBJK_LINK
connect to 用户名 identified by 密码
using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = IP地址)(PORT = 端口号 ))
)
(CONNECT_DATA =
(SERVICE_NAME = 实例名)
)
)';
注意:创建db_link时需注意数据库版本, select * from v$version; 低版本数据库访问高版本数据库创建db_link时,数据库密码要用“”引起来,不然密码会转换为大写。
-- 通过db_link查询数据库表
select * from 用户.表名@ESBJK_LINK t;
--删除db_link
DROP DATABASE LINK [name];
--或
DROP PUBLIC DATABASE LINK [name];