建立dblink访问远程数据库
通过建立dblink 对远程数据访问
配置1
1、首先在本地配置一个服务名,地址指向远程的数据库地址 需要在创建dblink 的DB上配置好tnsname.ora (该文件存放的位置为: $ORACLE_HOME/network/admin/tnsnames.ora),
把那个被连接的db信息加入进去:
JDMG=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST=10.16.9.98)(PORT=1527))
)
(CONNECT_DATA =
(SERVICE_NAME=jdmg)
)
)
2、测试:tnsping orcl
C:\Users\Administrator>tnsping jdmg
TNS Ping Utility for 32-bit Windows: Version 10.2.0.3.0 - Production on 08-3月 -2012 17:07:25
Copyright (c) 1997, 2006, Oracle. All rights reserved.
已使用的参数文件:
D:\oracle\product\10.2.0\db_1\network\admin\sqlnet.ora
已使用 TNSNAMES 适配器来解析别名
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST=10.16.9.98)(PORT=1527))) (CONNECT_DATA = (SERVICE_NAME=jdmg)))
OK (180 毫秒)
cmd中输出如上表示可以。
3、在数据库B中建立一个到数据库A的DBLINK (在pl/sql的Sql Window和Command Window运行命令即可)
create database link ciqlink connect to oaorg identified by fundo using 'jdmg';
格式:create database link dblink_name connect to user identified by password using ‘sid’;
4、通过dblink实现分布式查询
select country_cname from c_country_region@ciqlink;
配置2
create database link ciqlink connect to wleam identified by eamtest using '
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST=10.16.9.98)(PORT=1527))
)
(CONNECT_DATA =
(SERVICE_NAME=jdmg)
)
)
'