当前位置:首页 » 编程语言 » oracle访问sql

oracle访问sql

发布时间: 2023-09-19 09:29:58

1. oracle 直接访问sqlserver

1、在安装了ORACLE9i Standard Edition或者ORACLE9i Enterprise Edition的windows机器上(IP:192.168.0.2), 产品要选了透明网关(Oracle Transparent Gateway)里访问Microsoft SQL Server数据库

$ORACLE9I_HOME\tg4msql\admin下新写initpubs.ora和initnorthwind.ora配置文件.

initpubs.ora内容如下:

HS_FDS_CONNECT_INFO="SERVER=SQLSERVER_HOSTNMAE;DATABASE=pubs"

HS_DB_NAME=pubs

HS_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_HOME\network\admin 下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:\oracle\ora92)

(SID_NAME = test9)

)

(SID_DESC=

(SID_NAME=pubs)

(ORACLE_HOME=d:\Oracle\Ora92)

(PROGRAM=tg4msql)

)

(SID_DESC=

(SID_NAME=northwind)

(ORACLE_HOME=d:\Oracle\Ora92)

(PROGRAM=tg4msql)

)

)

重启动这台做gateway的windows机器上(IP:192.168.0.2)TNSListener服务.

(凡是按此步骤新增可访问的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)

访问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看从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_HOME\tg4msql\admin目录下的initsqlserver_databaseid.ora

WINDOWS下ORACLE9i网关服务器listener.ora里面

(SID_DESC=

(SID_NAME=sqlserver_databaseid)

(ORACLE_HOME=d:\Oracle\Ora92)

(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一致才行.
来自(http://www.enet.com.cn/article/2004/0212/A20040212285219.shtml)

2. oracle怎么用命令执行sql文件

Oracle执行外部文件:
c:>sqlplus user/pwd@db
sql>@new.sql
执行多个sql文件:
1.把所有的文件都放在同一个目录下,然后在命令行里执行命令:
c:>dir/b > d:/1.sql
会把所有的sql文件名都输出到一个sql文件中。
2.用UltraEdit打开生成的sql文件,alt+C切换到column mode,给所有的行前都添加一个"@",保存。
3.在sqlplus中执行"@d:/1.sql"
如何避免'&'字符:
sql中&可以传递参数,但有时需要插入'&',例:
SQL> select '&hello' v from al;
输入 hello 的值: hello
原值 1: select '&hello' v from al
新值 1: select 'hello' v from al
v
-----
hello
可以使用如下方法避免:
A:
SQL> select chr(38) || 'hello' v from al;
V
------
&hello
B:
SQL> set define off
SQL> select '&hello' v from al;
V
------
&hello

3. oracle怎么导入sql文件

  • PL/SQL登录到数据库,使用tools工具进行导入。使用plsql登录到需要导入数据的数据库。点击工具栏上【tools】--【Import tables】

热点内容
ftp服务器ui 发布:2025-02-02 06:24:15 浏览:102
wifi有多少种密码 发布:2025-02-02 06:22:06 浏览:585
app账号和密码忘了怎么办啊 发布:2025-02-02 06:21:58 浏览:103
map访问 发布:2025-02-02 06:09:07 浏览:825
android获取应用版本 发布:2025-02-02 05:54:19 浏览:747
pythonif比较 发布:2025-02-02 05:24:03 浏览:260
已连接的无线网如何知道密码 发布:2025-02-02 04:53:51 浏览:634
android编程入门经典pdf 发布:2025-02-02 04:46:19 浏览:57
安卓什么软件测试手机电池 发布:2025-02-02 04:28:52 浏览:996
手机上传快 发布:2025-02-02 04:27:46 浏览:308