你知道如何在Oracle SQL Server中设置访问多个相关的数据库?如果我们想要在Oracle SQL Server里同时访问的话,默认的有pubs与Northwind两个重要的数据库。以下就是相关内容的介绍。
成都创新互联公司专注于鹤庆网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供鹤庆营销型网站建设,鹤庆网站制作、鹤庆网页设计、鹤庆网站官网定制、成都小程序开发服务,打造鹤庆网络公司原创品牌,更为您提供鹤庆网站排名全网营销落地服务。
1、在安装了Oracle9i Standard Edition或者Oracle9i Enterprise Edition的windows机器上(IP:192.168.0.2), 产品要选了透明网关(Oracle Transparent Gateway)里访问Microsoft SQL Server数据库
ORACLE9I_HOMEtg4msqladmin下新写initpubs.ora和initnorthwind.ora配置文件.
initpubs.ora内容如下:
- HS_FDS_CONNECT_INFO="SERVER=SQLSERVER_HOSTNMAE; DATABASE=pubs"
- HS_DB_NAME=pubsHS_FDS_TRACE_LEVEL=OFF
- HS_FDS_RECOVERY_ACCOUNT=RECOVER
- HS_FDS_RECOVERY_PWD=RECOVER
initnorthwind.ora内容如下:
- HS_FDS_CONNECT_INFO="SERVER=sqlserver_hostname; DATABASE=Northwind"
- HS_DB_NAME=Northwind
- HS_FDS_TRACE_LEVEL=OFF
- HS_FDS_RECOVERY_ACCOUNT=RECOVER
- HS_FDS_RECOVERY_PWD=RECOVER
- $ORACLE9I_HOMEnetworkadmin 下listener.ora内容如下:
- LISTENER =
- (DESCRIPTION_LIST =
- (DESCRIPTION =
- (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
- )
- )
- )
- SID_LIST_LISTENER =
- (SID_LIST =
- (SID_DESC =
- (GLOBAL_DBNAME = test9)
- (ORACLE_HOME = d:oracleora92)
- (SID_NAME = test9)
- )
- (SID_DESC=
- (SID_NAME=pubs)
- (ORACLE_HOME=d:OracleOra92)
- (PROGRAM=tg4msql)
- )
- (SID_DESC=
- (SID_NAME=northwind)
- (ORACLE_HOME=d:OracleOra92)
- (PROGRAM=tg4msql)
- )
- )
重启动这台做gateway的Windows机器上(IP:192.168.0.2)TNSListener服务(凡是按此步骤新增可访问的Oracle SQL Server数据库时,TNSListener服务都要重启动)。
2、Oracle8i,Oracle9i的服务器端配置tnsnames.ora, 添加下面的内容:
- pubs =
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
- )
- (CONNECT_DATA =
- (SID = pubs)
- )
- (HS = pubs)
- )
- northwind =
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
- )
- (CONNECT_DATA =
- (SID = northwind)
- )
- (HS = northwind) )
保存tnsnames.ora后,在命令行下
- tnsping pubs
- tnsping northwind
出现类似提示,即为成功:
- Attempting to contact (DESCRIPTION = (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)
- (PORT = 1521))) (CONNECT_DATA = (SID = pubs)) (HS = pubs))
- OK(20毫秒)
- Attempting to contact (DESCRIPTION = (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)
- (PORT = 1521)))
- (CONNECT_DATA = (SID = northwind)) (HS = northwind))OK(
20毫秒)
设置数据库参数global_names=false。
设置global_names=false不要求建立的数据库链接和目的数据库的全局名称一致。global_names=true则要求, 多少有些不方便。
oracle9i和oracle8i都可以在DBA用户下用SQL命令改变global_names参数
- alter system set global_names=false;
建立公有的数据库链接:
- create public database link pubs
- connect to testuser identified by testuser_pwd using 'pubs';
- create public database link northwind
- connect to testuser identified by testuser_pwd using 'northwind';
(假设SQL Server下pubs和northwind已有足够权限的用户登陆testuser,密码为testuser_pwd)
访问Oracle SQL Server下数据库里的数据:
- select * from stores@pubs;
- ...... ......select *
- from region@northwind;
3、使用时的注意事项
ORACLE通过访问SQL Server的数据库链接时,用select * 的时候字段名是用双引号引起来的。
例如:
- create table stores as select * from stores@pubs;
- select zip from stores;
ERROR 位于第 1 行:
ORA-00904: 无效列名
- select "zip" from stores;
- zip
- -----
- 98056
- 92789
- 96745
- 98014
- 90019
- 89076
已选择6行,用SQL Navigator或Toad看从Oracle SQL Server转移到ORACLE里的表的建表语句为:
- CREATE TABLE stores
- ("stor_id" CHAR(4) NOT NULL,
- "stor_name" VARCHAR2(40),
- "stor_address" VARCHAR2(40),
- "city" VARCHAR2(20),
- "state" CHAR(2),
- "zip" CHAR(5))
- PCTFREE 10
- PCTUSED 40
- INITRANS 1
- MAXTRANS 255
- TABLESPACE users
- STORAGE (
- INITIAL 131072
- NEXT 131072
- PCTINCREASE 0
- MINEXTENTS 1
- MAXEXTENTS 2147483645
- )
总结:
Windows下Oracle9i网关服务器在$Oracle9i_HOMEtg4msqladmin目录下的initsqlserver_databaseid.ora。Windows下Oracle9i网关服务器listener.ora里面:
- (SID_DESC=
- (SID_NAME=sqlserver_databaseid)
- (ORACLE_HOME=d:OracleOra92)
- (PROGRAM=tg4msql)
- )
UNIX或WINDOWS下ORACLE8I,ORACLE9I服务器tnsnames.ora里面
- northwind =
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
- )
- (CONNECT_DATA =
- (SID = sqlserver_databaseid)
- )
- (HS = sqlserver_databaseid)
- )
需要sqlserver_databaseid一致才行。2007-11-14 来自:xuejinyoulan [收藏到我的网摘]
当前文章:OracleSQLServer设置访问多个数据库的方案
文章分享:http://www.shufengxianlan.com/qtweb/news41/527791.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联