Chinaunix首页 | 论坛 | 博客
  • 博客访问: 104674927
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: Oracle

2008-05-22 17:08:04

来源:

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=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)

访问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
阅读(230) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~