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*/databaselink tong connectto 远程用户名 identifiedby 密码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; --查看数据库有多少dblinkOWNER DB_LINK USERNAME HOST CREATEDSYS TONG1 UPCH (DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL = TCP)(HOST = 172.16.8.161)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = orcl))) 28-JUN-17sql> drop database link tong1; --删除dblinkDatabase link dropped.sql>

相关文章

数据库版本:11.2.0.4 RAC(1)问题现象从EM里面可以看到,在23号早上8:45~8:55时,数据库等待会话暴增...
(一)问题背景最近在对一个大约200万行数据的表查看执行计划时,发现存在异常,理论上应该返回100多万...
(一)删除备份--DELETE命令用于删除RMAN备份记录及相应的物理文件。当使用RMAN执行备份操作时,会在RM...
(1)DRA介绍 数据恢复顾问(Data Recovery Advise)是一个诊断和修复数据库的工具,DRA能够修复数据文...
RMAN(Recovery Manager)是Oracle恢复管理器的简称,是集数据库备份(backup)、修复(restore)和恢复...
(1)备份对象 可以使用RMAN进行的备份对象如下: --整个数据库:备份所有的数据文件和控制文件; --数...