Oracle 创建数据库链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41477825/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:22:03  来源:igfitidea点击:

Oracle creating Database link

databaseoracleexpress

提问by poonam

I am using Oracle 11g express edition. I have created tables, stored procedures and it works fine. I have my user "System" with password "xyz" (main user during installation).

我正在使用 Oracle 11g 快速版。我已经创建了表、存储过程并且它工作正常。我有我的用户“系统”,密码为“xyz”(安装期间的主用户)。

Then i have created two databases "abc" and "pqr" with same user.

然后我用同一个用户创建了两个数据库“abc”和“pqr”。

I wanted to create database link from abc to pqr.

我想创建从 abc 到 pqr 的数据库链接。

create database link testlink
connect to pqr identified by xyz
 using '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))   (CONNECT_DATA=(sid=xe)))';

I am getting error "Insufficient privileges". Please help me out.

我收到错误“权限不足”。请帮帮我。

回答by JSapkota

It should be CONNECT TOusername not the database name as shown in the following image which describes the syntax of CREATE DATABASE LINK. We define database instance/service under USING connect_stringclause.

它应该是CONNECT TO用户名而不是数据库名称,如下图所示,它描述了CREATE DATABASE LINK. 我们在USING connect_string子句下定义数据库实例/服务。

enter image description here

在此处输入图片说明

Prerequisites

To create a private database link, you must have the CREATE DATABASE LINKsystem privilege. To create a public database link, you must have the CREATE PUBLIC DATABASE LINKsystem privilege. Also, you must have the CREATE SESSIONsystem privilege on the remote Oracle database.

先决条件

要创建私有数据库链接,您必须具有CREATE DATABASE LINK系统权限。要创建公共数据库链接,您必须具有CREATE PUBLIC DATABASE LINK系统权限。此外,您必须具有CREATE SESSION远程 Oracle 数据库的系统权限。

Reference:CREATE DATABASE LINK

参考:创建数据库链接

Demo

演示

[oracle@orcl Desktop]$ sqlplus system/oracle

SQL> create user abc identified by abc;

User created.

SQL> create user xyz identified by xyz;

User created.

SQL> grant create session to abc;

Grant succeeded.

SQL> conn abc/abc
Connected.

SQL> create database link testlink connect to pqr identified by pqr using '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=orcl.dba.com)(PORT=1522))   (CONNECT_DATA=(service=orcl)))';
create database link testlink connect to pqr identified by pqr using '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=orcl.dba.com)(PORT=1522))   (CONNECT_DATA=(service=orcl)))'
                     *
ERROR at line 1:
ORA-01031: insufficient privileges


SQL> conn system/oracle
Connected.
SQL> grant create database link to abc;

Grant succeeded.

SQL> create database link testlink connect to pqr identified by pqr using '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=orcl.dba.com)(PORT=1522))   (CONNECT_DATA=(service=orcl)))';^[[3~^C

SQL> conn abc/abc
Connected.
SQL> create database link testlink connect to pqr identified by pqr using '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=orcl.dba.com)(PORT=1522))   (CONNECT_DATA=(service=orcl)))';

Database link created.