关于DBLink for 2数据库oracle的问题

问题描述 投票:0回答:2

我有一个带有2个数据库的服务器:dbtest和checkdb。我需要dbtest的用户user_b可以在其他数据库的表上进行选择。我如何设置dblink?

database oracle dblink
2个回答
0
投票

在脚本运行的顶部

alter session set global_names=false;

然后,无论何时需要从checkdb获取数据,都要将链接添加为后缀。不知道你的dbs是如何定义的,但是类似的东西

user_b在dbtest上

select * from table_name@dblink 
#might be that dblink is not the exact name. 

希望能帮助到你。


0
投票

以其中一个数据库中的用户身份连接,按照语法(https://docs.oracle.com/en/database/oracle/oracle-database/18/sqlrf/CREATE-DATABASE-LINK.html#GUID-D966642A-B19E-449D-9968-1121AF06D793)创建到另一个数据库的数据库链接。我想,它没有改变多年。

例如:

SQL> create database link dbl_scott     -- database link name
  2    connect to scott                 -- you're connecting to this user (scott) ...
  3    identified by tiger              -- ... which is identified by this password (tiger)
  4    using 'db11g:1521/orcl';         -- using clause has a database server (db11g):port (1521)/service name (orcl)

Database link created.

SQL> -- Testing; it has to return a row
SQL> select * From dual@dbl_scott; 

D
-
X

SQL>

可以通过放置目标数据库别名(在数据库服务器上用USING文件编写的别名)来缩短TNSNAMES.ORA子句。如果您无权访问该文件(因为您不是DBA),则上述选项可以正常工作。

请注意 - 即使您使用无效设置 - 可能会创建数据库链接,但它不起作用。例如:

SQL> drop database link dbl_scott;

Database link dropped.

SQL> create database link dbl_scott
  2    connect to xyzalksfjlaskfj
  3    identified by abc
  4    using '9809803242';

Database link created.

SQL> select * from dual@dbl_scott;
select * from dual@dbl_scott
                   *
ERROR at line 1:
ORA-12154: TNS:could not resolve the connect identifier specified


SQL>

因此,要小心。

© www.soinside.com 2019 - 2024. All rights reserved.