转载自:http://apple-wxs.javaeye.com/blog/281072
如果想从主机A 操作主机B 上的数据,可以在主机A上建立一个dblink,link到主机B上,从而操作主机B上的数据。
主机A的tnsnames.ora中配置了主机B的信息
- TEST =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.134)(PORT = 1521))
- (CONNECT_DATA =
- (SERVICE_NAME = bs)
- (INSTANCE_NAME = bs)
- )
- )
TEST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.134)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = bs)
(INSTANCE_NAME = bs)
)
)
注:sid:TEST 服务名:bs(通过sid能知道连接的IP,端口)
建立dblink的语法:
create database link link名
connect to 登陆主机B的用户名(没有引号) identified by 登陆主机B的密码
using '主机B在主机A中的tnsnames.ora中配置的sid';
- --删除dblink
- drop database link link_test;
- --建立dblink
- create database link link_test
- connect to apple_wxs identified by apple_wxs
- using 'TEST';
- --查询主机B 上的XXX_t表
- select * from XXX_t@link_test;
--删除dblink
drop database link link_test;
--建立dblink
create database link link_test
connect to apple_wxs identified by apple_wxs
using 'TEST';
--查询主机B 上的XXX_t表
select * from XXX_t@link_test;
主机A上的tnsnames.ora中没有配置主机B的sid或不知道的情况
- CREATE PUBLIC DATABASE LINK link名
- CONNECT TO username IDENTIFIED BY password
- USING '(DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.134)(PORT = 1521))
- )
- (CONNECT_DATA =
- (SERVICE_NAME = bs)
- )
- )';