Home  >  Article  >  Database  >  Oracle DBLink使用

Oracle DBLink使用

WBOY
WBOYOriginal
2016-06-07 17:29:091096browse

Oracle DbLink测试 源数据库: 计算机名:beijing 数据库名:orcl 目标数据库: 计算机名:suzhou 数据库名:ocp 0.目标数据库新建测

Oracle DbLink测试

源数据库:

计算机名:beijing

数据库名:orcl

目标数据库:

计算机名:suzhou

数据库名:ocp

0.目标数据库新建测试表

SQL> conn scott/password

已连接。

SQL> show user;

USER 为 "SCOTT"

SQL> create table t1

2 (

3 sid int not null,

4 sno int

5 );

表已创建。

SQL> insert into t1 values (101,201);

已创建 1 行。

SQL> commit;

提交完成。

SQL> select * from t1;

SID SNO

---------- ----------

101 201

1.源数据库上修改tnames.ora

to_suzhou =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.90.20)(PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = ocp)

)

)

2.源数据库上新建链接

create public database link DB_LINK_NAME connect to TargetDatabaseUserName identified by TargetDatabasePassword using 'TargetDatabaseSIDName';

注:TargetDatabaseSIDName为该Oracle数据库所在的主机上的tnsnames.ora文件里边定义的数据库连接串()。

create public database link to_sz connect to scott identified by password using 'to_suzhou';

3.测试db link

SQL> select * from t1@to_sz;

SID SNO

---------- ----------

101 201

4.创建同义词,

SQL> create synonym dblinktest for t1@to_sz;

Synonym created.

SQL>select * from dblinktest;

5查看数据库的链接

SQL> select owner,object_name from dba_objects where object_type='DATABASE LINK';

6删除数据库连接

SQL> drop public database link to_sz;

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn