oracle-2_dblink的创建和使用
一、创建dblink
1、查询创建dblink表
SELECT * FROM DBA_DB_LINKS;
DECLARE I NUMBER(22); BEGIN SELECT COUNT(*) INTO I FROM DBA_DB_LINKS WHERE DB_LINK = 'ZSZQ_DBLINKNEW'; IF I=0 THEN EXECUTE IMMEDIATE 'CREATE DATABASE LINK ZSZQ_DBLINKNEW CONNECT TO "EMPZSZQ" identified by "123456" USING ''(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.169.0.42)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = ZSZQ) ))'''; END IF; END; /
2、字段解释
ZSZQ_DBLINKNEW:dblink名称
EMPZSZQ:数据库用户名
123456:数据库密码
192.169.0.42:数据库ip地址
1521:orale数据库端口
ZSZQ:数据库实例名
3、dblink的用法
select * from tb_cpzx_vpif_cpdm_wms@zszq_dblinknew where id =109981;
注:
tb_cpzx_vpif_cpdm_wms:数据库中表名称
zszq_dblinknew:dblink中名称,对应表DBA_DB_LINKS中字段DB_LINK