可以从两个不同的DB2数据库中加入数据吗? (像SQL Server链接的数据库) [英] Can I join data from 2 different DB2 databases? (Like SQL Server linked databases)

查看:175
本文介绍了可以从两个不同的DB2数据库中加入数据吗? (像SQL Server链接的数据库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在加强现有的java应用程序。有两个不同的DB2数据库中有数据。该应用程序已经从两个不同的数据库获取数据,但它始终从一个然后另一个查找。有没有办法使用一个SQL SELECT从两个不同的DB2数据库中加入数据?



这是我试过的:

  CREATE ALIAS remote_orders FOR remote_db.schema.orders; 

select *
from myid.remote_orders a
inner join local_schema.parts b on(a.key = b.key)
with ur FETCH FIRST 200 ROWS ONLY

我收到此错误:

 对远程对象的声明参考无效。 SQLCODE = -512,SQLSTATE = 56023,DRIVER = 4.14.113 

我可以用temp表?我可以运行这个选择没有错误,但它不帮助我...(还)

  select * 
from myid.remote_orders
with ur FETCH FIRST 200 ROWS ONLY

编辑:



DB2 Temp Table 可能有帮助。我能够创建一个。现在我需要(去睡觉),然后尝试选择它,然后进行加入。

解决方案

使用完全限定名称< database>。< user / schema>。< tablename>





  select * 
from DB1.myid.remote_orders a
inner join DB2.local_schema.parts b on(a.key = b.key)
with ur FETCH FIRST 200 ROWS ONLY


I'm enhancing an existing java application. There is data in 2 different DB2 databases. The app already gets data from 2 different databases, but it always does a lookup from one and then the other. Is there a way to join data from 2 different DB2 databases using one SQL SELECT?

This is what I tried:

CREATE ALIAS remote_orders FOR remote_db.schema.orders;

select *
from myid.remote_orders a
inner join local_schema.parts b on (a.key = b.key)
with ur FETCH FIRST 200 ROWS ONLY

I get this error:

STATEMENT REFERENCE TO REMOTE OBJECT IS INVALID. SQLCODE=-512, SQLSTATE=56023, DRIVER=4.14.113

Can I do something with a temp table? I can run this select with no errors, but it does not help me... (yet)

select *
from myid.remote_orders
with ur FETCH FIRST 200 ROWS ONLY

EDIT:

A DB2 Temp Table might help. I was able to create one. Now I need to (go to bed) and try selecting into it and THEN doing my join.

解决方案

Use fully qualified name <database>.<user/schema>.<tablename>

something like:

select *
from DB1.myid.remote_orders a
inner join DB2.local_schema.parts b on (a.key = b.key)
with ur FETCH FIRST 200 ROWS ONLY

这篇关于可以从两个不同的DB2数据库中加入数据吗? (像SQL Server链接的数据库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆