你是要 dblink 到另外一个 oracle? 还是 dblink 到一个 sql server ?
注:
如果创建全局dblink,必须使用systm或sys用户,在database前加public。
SQL> CREATE DATABASE LINK mydblink
2 CONNECT TO test IDENTIFIED BY test123
3 USING '(DESCRIPTION =
4 (ADDRESS_LIST =
5 (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.210)(PORT = 1521)))
6 (CONNECT_DATA = (SERVICE_NAME = orcl)
7 )
8 )'
Database link created.
SQL> select count(1) from user_tables@mydblink
COUNT(1)
----------
6
上面的例子,是在当前 Oracle 数据库上面,创建一个 名字叫 mydblink 的数据库链接。
使用 test作为用户名,test123 作为密码。
访问的远程数据库,ip地址是 192.168.1.210,端口号是默认的 1521
远程服务器的服务名是 orcl
Oracle 连接 SQL Server
需要去下载 额外的 网关程序
注意:
本次测试
Oracle (10.2.0.1.0) 服务器 ip 地址: 192.168.1.210
SQL Server (2005 开发者版本) 服务器名(SQL2005)
下载下来的
10201_gateways_win32.zip
该 gateways 程序
可安装在 SQL Server 那台计算机上
本次网关程序,被安装在
D:\oracle\product\10.2.0\tg_1
目录下.
安装过程会提示输入 SQL Server 数据库的信息。
该信息会被生成在
D:\oracle\product\10.2.0\tg_1\tg4msql\admin
目录下的
inittg4msql.ora
文件中。
将其复制粘贴为文件名
initTest2005.ora
然后修改内容
# This is a sample agent init file that contains the HS parameters that are
# needed for the Transparent Gateway for SQL Server
#
# HS init parameters
#
HS_FDS_CONNECT_INFO=SQL2005.test
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER
下一步,修改
D:\oracle\product\10.2.0\tg_1\NETWORK\ADMIN
目录下的
listener.ora
文件。
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = D:\oracle\product\10.2.0\tg_1)
(PROGRAM = extproc)
)
# 追加开始
(SID_DESC =
(SID_NAME = Test2005)
(ORACLE_HOME = D:\oracle\product\10.2.0\tg_1)
(PROGRAM = tg4msql)
)
# 追加结束
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = SQL2005)(PORT = 1521))
)
)
下一步,运行 lsnrctl stop / lsnrctl start
C:\>lsnrctl stop
输出略...
C:\>lsnrctl start
部分输出略...
服务 "Test2005" 包含 1 个例程。
例程 "Test2005", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
命令执行成功
下一步,修改
D:\oracle\product\10.2.0\tg_1\NETWORK\ADMIN
目录下的
tnsnames.ora
文件
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
# 追加开始
TEST2005 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = SQL2005)(PORT = 1521))
)
(CONNECT_DATA =
(SID = Test2005)
)
(HS = OK)
)
# 追加结束
tnsping 测试是否正常。
C:\>tnsping test2005
TNS Ping Utility for 32-bit Windows: Version 10.2.0.1.0 - Production on 03-10月-
2011 14:03:03
Copyright (c) 1997, 2005, Oracle. All rights reserved.
已使用的参数文件:
D:\oracle\product\10.2.0\tg_1\network\admin\sqlnet.ora
已使用 TNSNAMES 适配器来解析别名
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)
(HOST = SQL2005)(PORT = 1521))) (CONNECT_DATA = (SID = Test2005)) (HS = OK))
OK (50 毫秒)
创建数据库链接 (DBLINK)
CREATE DATABASE LINK mssql2005
CONNECT TO "test" IDENTIFIED BY "test123"
USING '(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = SQL2005)(PORT = 1521))
(CONNECT_DATA = (SID = Test2005)
(HS = OK)
)
)'
SELECT * FROM test@mssql2005
创建公开数据库链接CREATE
PUBLIC
DATABASE
LINK
“数据库链接别名”
CONNECT
TO
“登陆用户”
IDENTIFIED
BY
“登陆密码”
USING
'(DESCRIPTION
=(ADDRESS_LIST
=(ADDRESS
=(PROTOCOL
=
TCP)(HOST
=
IP)(PORT
=
1521)))(CONNECT_DATA
=(SID
=
SID)))'
例如:
CREATE
PUBLIC
DATABASE
LINK
MYDBLINK
CONNECT
TO
USER1
IDENTIFIED
BY
PASSWORD1
USING
'(DESCRIPTION
=(ADDRESS_LIST
=(ADDRESS
=(PROTOCOL
=
TCP)(HOST
=
10.10.10.10)(PORT
=
1521)))(CONNECT_DATA
=(SID
=
ORA10)))'
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)