Oracle Apex IG 查询来比较 2 个表

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

我需要编写 IG 查询来比较两个具有相同结构但在不同数据库中的表。

在当地我们有:

select emp_id,emp_name,emp_grade,emp_org,emp_unit from employees;

在目标数据库中我们有:

select emp_id,emp_name,emp_grade,emp_org,emp_unit from employees@dest_db;

我需要显示与employees@dest_db 存在差异的所有行以及employees@dest_db 中存在但不存在employees 的行。

我尝试使用案例:

select emp_id,emp_name,emp_grade,emp_org,emp_unit,
case when a.emp_id=b.emp_id then 1 else 0 end empid_match ,
case when a.emp_name=b.emp_name then 1 else 0 end emp_name_match ,
case when a.emp_grade=b.emp_grade then 1 else 0 end emp_grade_match ,
case when a.emp_org=b.emp_org then 1 else 0 end emporg_match ,
case when a.emp_unit=b.emp_unit then 1 else 0 end emp_unit_match ,
 from employees@dest_db a, employees b 
where a.emp_id = b.emp_id;

但这只会返回有差异的行并突出显示它们。 我在 IG 中为 empid_match 等值添加了条件,以突出显示 if 1。

但是我如何修改查询以返回employees@dest_db中存在的行而不是employees?

sql oracle-apex
1个回答
0
投票

我如何修改查询以返回employees@dest_db中存在的行而不是employees?

看起来像是外连接问题。从此

修改
FROM

子句
from employees@dest_db a, employees b where a.emp_id = b.emp_id

from employees@dest_db a left join employees b on a.emp_id = b.emp_id
                         ---------
                         this

或者,如果您更喜欢 Oracle 的外连接语法,

from employees@dest_db a, employees b where a.emp_id = b.emp_id (+)
                                                                ---
                                                                this
© www.soinside.com 2019 - 2024. All rights reserved.