摘要:本文写了个在Oracle中创建DBLink的示例。
从本地数据库L建立DBLink连接到一个远程数据库R,创建语句如下:
CREATE DATABASE LINK MyDBLink CONNECT TO user_name IDENTIFIED BY password USING 'name'
MyDbLink:创建的DBLink名称。
user_name:是远程数据库R的用户名。
password:是远程数据库R的密码。
name:是远程数据R在本机tnsnames.ora文件中设置的名称。
如果本地没有装数据库,可以换成下面的方式:
CREATE DATABASE LINK MyDBLink CONNECT TO user_name IDENTIFIED BY password USING
'(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.119.0.161)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = smes30)
)
)';
直接将tnsnames.ora文件中的内容作为USING的参数。
下面给出几个tnsnames.ora文件的格式:
ORALOCAL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oralocal)
)
)
ORALOCAL_2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = oralocal)
)