1

我的问题很简单,假设我在两个表之间加入,其中一个是右加入

select e.name, nvl(e.mobileNumber, c.secondaryNumber)
from T_employee e, t_contact c
where e.fieldOfficeCode = 10
and e.id = c.id (+)
and c.status = 1001

现在,如果我删除查询的最后一行,它将正确连接,但是一旦出现最后一行,我将不会得到任何结果。关于如何解决这个问题的任何想法。现在手头的查询相对复杂,跨越 5 个表,但示例片段将简化实际问题

问候,

4

2 回答 2

3

这就是你需要的:

and c.status (+) = 1001

或者用现代语法:

select e.name, nvl(e.mobileNumber, c.secondaryNumber)
from T_employee e
left outer join t_contact c
  on e.id = c.id
  and c.status = 1001
where e.fieldOfficeCode = 10

您的查询通过仅选择 c.status= 1001 的连接记录将外连接重新转换为内连接 - 它排除了所有为空的不匹配行。

于 2012-07-16T09:33:50.887 回答
0

试试这个

select e.name, nvl(e.mobileNumber, c.secondaryNumber) 
from T_employee e right join  t_contact c 
on and e.id = c.id (+) and c.status = 1001 
where e.fieldOfficeCode = 10 
于 2012-07-16T09:30:34.320 回答