用于创建另一个用户拥有的数据库链接的 Oracle 语法
创建数据库链接的典型语法如下:
create database link remote_db_link
connect to remote_user
identified by remote_password
using 'remote_db'
但我希望我的数据库链接在创建后由另一个帐户拥有。 有没有办法做到这一点?
以下不起作用:
create database link anotheruser.remote_db_link
connect to remote_user
identified by remote_password
using 'remote_db'
The typical syntax for creating a db link is as follows:
create database link remote_db_link
connect to remote_user
identified by remote_password
using 'remote_db'
But I'd like my DB link owned by another account after it's created. Is there a way to do this?
The following does NOT work:
create database link anotheruser.remote_db_link
connect to remote_user
identified by remote_password
using 'remote_db'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Sathya 是正确的,因为
CREATE DATABASE LINK
语法不允许在另一个模式中创建数据库链接。 但是...解决方法
只要
anotheruser
具有CREATE DATABASE LINK,IS就可以在另一个用户的架构中创建数据库链接
权限,并且您连接的用户具有CREATE ANY PROCEDURE
权限。这是我使用的解决方法:
让我们放松一下。 首先,我在
anotherusers
的架构中创建一个过程; 此过程包含我要运行的CREATE DATABASE LINK
语句。执行该过程时,它以该过程的所有者身份运行,因此
CREATE DATABASE LINK
语句由anotheruser
执行。过程的名称并不重要,只是我需要确保它不与任何现有的对象名称冲突。 我使用小写字母(将过程名称括在双引号中),使用“tmp”将此对象标记为“临时”,并使用当前的 yyyymmddhh24miss 作为过程名称的一部分。 (我通常运行 DBA_OBJECTS 查询来检查匹配的 object_name 是否不存在。)
对于“一次性”类型的管理功能,这是一种可行的解决方法。 与其他选择相比,我更喜欢这种方法:保存另一个用户的密码,更改密码,以用户身份连接,然后将另一个用户的密码重置回保存的密码。)
Sathya is correct, in that the
CREATE DATABASE LINK
syntax does not allow creating a database link in another schema. HOWEVER...WORKAROUND
It IS possible to create a database link in another user's schema, as long as
anotheruser
hasCREATE DATABASE LINK
privilege, and the user you are connected as hasCREATE ANY PROCEDURE
privilege.Here's the workaround I use:
Let's unwind that. First, I create a procedure in the
anotherusers
's schema; this procedure contains theCREATE DATABASE LINK
statement that I want to run.When the procedure is executed, it runs as the owner of the procedure, such that the
CREATE DATABASE LINK
statement is executed byanotheruser
.The name of the procedure is not important, except that I need to make sure that it doesn't conflict with any existing object name. I use lowercase letters (enclosing the procedure name in double quotes), using "tmp" to mark this object as "temporary", and using the current yyyymmddhh24miss as the part of the procedure name. (I usually run a query of DBA_OBJECTS to check that a matching object_name does not exist.)
For a "one-off" type admin function, this is a viable workaround. I prefer this to the other alternative: saving the anotheruser's password, changing the password, connecting as the user, and resetting anotheruser's password back to the saved.)
DBLink 的限制 - 您无法创建数据库链接在另一个用户的模式中,并且您不能使用模式名称限定 dblink。
Restrictions on DBLinks - You cannot create a database link in another user's schema, and you cannot qualify dblink with the name of a schema.
作为 sys 用户,您可以在 SYS.DBA_DB_LINKS 视图中查看所有数据库链接。
该视图使用 link$ 和 user$ 表。
您可以像往常一样创建新的 dblink,它显示在 link$ 表中。 然后更改所有者(使用 user$ 中的 id)。 犯罪。 完毕。
AS a sys user you can view all db links in SYS.DBA_DB_LINKS view.
That view use link$ and user$ table.
You can create new dblink as usually and it show at link$ table. Then change owner (use id from user$). commit. Done.