dblink的使用

1.创建全局link(使用本地一个用户访问其它用户的表)

语法:

create public database link 链接名  CONNECT TO 本地用户名 IDENTIFIED BY 密码 USING '本地数据库实例名';

SQL> create user upch identified by System13579;         
User created.
SQL> grant dba,resource,connect to upch;
Grant succeeded.

SQL> conn upch/System13579
Connected.

SQL> create table t (a number);
Table created.

SQL> insert into t values(1);
1 row created.
SQL> insert into t values(2);
1 row created.
SQL> select * from t;
     A
----------
     1
     2
SQL> conn / as sysdba
Connected.

SQL> create public database link tong connect to upch identified by System13579 using 'orcl';

SQL> select * from t@tong;    --访问upch用户下的t表
     A
----------
     1
     2
SQL>


2.远程创建link

语法:

create /* public */ database link tong connect to 远程用户名 identified by 密码using '(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL = TCP)(HOST = 远程IP地址)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = 远程SID值)))'; 

[oracle@localhost dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Wed Jun 28 14:47:53 2017
Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create database link tong1 connect to upch identified by System13579 using '(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL = TCP)(HOST = 172.16.8.161)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = orcl)))';
Database link created.
SQL> select * from t@tong1;
     A
----------
     1
     2
SQL> col owner for a10

SQL> col db_link for a10

SQL> col host for a150

SQL> select * from dba_db_links;        --查看数据库有多少dblink
OWNER  DB_LINK  USERNAME     HOST       CREATED
SYS    TONG1    UPCH      (DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL = TCP)(HOST = 172.16.8.161)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = orcl)))            28-JUN-17
SQL> drop database link tong1;            --删除dblink
Database link dropped.
SQL>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值