从 sqldeveloper 中的不同 oracle 连接查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9379722/
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-10 03:58:37  来源:igfitidea点击:

query from different oracle connections in sqldeveloper

oracleoracle-sqldeveloper

提问by user999379

I have 2 connections with different tables in sqldeveloper.

我在 sqldeveloper 中有 2 个与不同表的连接。

let's say:

让我们说:

ConnectionA with tables: A,B,C ConnectionB with tables: D,E,F

带表的连接A:A、B、C 带表的连接B:D、E、F

Now I want to have a query that looks like this:

现在我想要一个看起来像这样的查询:

select aa.name,dd.id from A aa,D dd;

从 A aa,D dd 中选择 aa.name,dd.id;

How can i do this?

我怎样才能做到这一点?

回答by Justin Cave

If you want to query objects in two different databases using a single SQL statement, you would need to create a database link between the two databases. A database link is an object that resides in the database and is independent of the query tool. In database A, for example, you could create the database link

如果要使用单个 SQL 语句查询两个不同数据库中的对象,则需要在两个数据库之间创建数据库链接。数据库链接是驻留在数据库中的对象,独立于查询工具。例如,在数据库 A 中,您可以创建数据库链接

CREATE DATABASE LINK to_b
  CONNECT TO username IDENTIFIED BY password
  USING tns_alias_on_a_pointing_to_b

And then when you connect to A, you could do something like

然后当你连接到 A 时,你可以做类似的事情

SELECT aa.name, dd.id
  FROM a aa,
       d@to_b dd
 WHERE aa.some_key = dd.some_key

回答by David Bala?ic

Apparently TOAD Data Pointsupports Cross-Connection Queries, see:

显然TOAD 数据点支持Cross-Connection Queries,请参阅:

http://dev.toadfordataanalyst.com/webhelp/Content/Query_Builder/Create_CrossConnection_Queries.htm

http://dev.toadfordataanalyst.com/webhelp/Content/Query_Builder/Create_CrossConnection_Queries.htm

Also Oracle SQL Developerseems to support something similar. (see this blog post: Cross Connection Queries)

此外Oracle SQL Developer中似乎支持类似的东西。(请参阅此博客文章:交叉连接查询

回答by sb4

I found this helpful and to the point of the OP question for Oracle 11g rel 2 and later: http://www.dba-oracle.com/t_how_create_database_link.htm. Basically, right-click on the connection in the Connections pane in SQL Developer, click Properties, and you get the hostname, port, and service name that you can plug into the "USING" part of the CREATE DATABASE LINK statement. Whether you put in Service Name or SID I assume depends on which you used in your connection. example:

我发现这对 Oracle 11g rel 2 及更高版本的 OP 问题很有帮助:http: //www.dba-oracle.com/t_how_create_database_link.htm。基本上,在 SQL Developer 的 Connections 窗格中右键单击该连接,单击 Properties,您将获得主机名、端口和服务名称,您可以将它们插入 CREATE DATABASE LINK 语句的“USING”部分。我假设您是输入服务名称还是 SID 取决于您在连接中使用的名称。例子:

create public database link mylink connect to remote_username identified by mypassword using 'myserver:1521/MYSID';

create public database link mylink connect to remote_username identified by mypassword using 'myserver:1521/MYSID';