0
select
  whatever
from
  bank_accs b1,
  bank_accs b2,
  table3 t3
where
  t3.bank_acc_id = t1.bank_acc_id and
  b2.bank_acc_number = b1.bank_acc_number and
  b2.currency_code(+) = t3.buy_currency and
  trunc(sysdate) between nvl(b2.start_date, trunc(sysdate)) and nvl(b2.end_date, trunc(sysdate));

我的问题是 b2 上的日期(实际情况)检查。现在,我需要为每个 t3xb1 返回一行(当然,t3 = ~10 个加入的表),即使 b2 中只有无效记录(按日期计算)。我如何正确地外部加入这个位?不能使用 ANSI 连接,必须在单个平面查询中使用。谢谢。

4

2 回答 2

0

If I understand you, just add the outer sign(+) to all columns of b2:

select
  whatever
from
  bank_accs b1,
  bank_accs b2,
  table3 t3
where
  t3.bank_acc_id = t1.bank_acc_id and
  b2.bank_acc_number = b1.bank_acc_number and
  b2.currency_code(+) = t3.buy_currency and
  trunc(sysdate) between nvl(b2.start_date(+), trunc(sysdate)) and nvl(b2.end_date(+), trunc(sysdate));
于 2012-09-06T09:55:52.230 回答
0

可以编写带有不等式的旧式外连接,但容易出错。我建议您使用内联视图,并且外部连接将清晰明确:

SELECT whatever
  FROM bank_accs b1,
       table3 t3,
       (SELECT b2.*
          FROM bank_accs b2
         WHERE trunc(sysdate) BETWEEN nvl(b2.start_date, trunc(sysdate)) 
                                  AND nvl(b2.end_date, trunc(sysdate))
       ) b2
 WHERE t3.bank_acc_id = t1.bank_acc_id
   AND b2.bank_acc_number = b1.bank_acc_number
   AND b2.currency_code(+) = t3.buy_currency;
于 2012-09-06T09:59:40.503 回答