在复杂的外连接表达式中,您可以将(+)
运算符放在所有相关列上,如下所示:
AND D.IFSC_CODE=UPPER(substr(B.BANK_CODE (+),1,4))
例如:
SQL> WITH table_a AS (
2 SELECT '0001' ID FROM dual
3 UNION ALL SELECT '0002' FROM dual
4 UNION ALL SELECT '0003' FROM dual
5 ), table_b AS (
6 SELECT '0001a' ID FROM dual
7 UNION ALL SELECT '0002b' FROM dual
8 )
9 SELECT a.id, b.id
10 FROM table_a a, table_b b
11 WHERE a.id = substr(b.id (+), 1, 4);
ID ID
---- -----
0001 0001a
0002 0002b
0003
这种形式的外连接是 Oracle 特有的,可以说比 SQL ANSI 外连接更难阅读。此外,这种旧方法禁用了某些特定功能(完全外连接,外连接到多个表)。在 SQL ansi 连接形式中,查询如下所示:
SQL> WITH table_a AS (
2 SELECT '0001' ID FROM dual
3 UNION ALL SELECT '0002' FROM dual
4 UNION ALL SELECT '0003' FROM dual
5 ), table_b AS (
6 SELECT '0001a' ID FROM dual
7 UNION ALL SELECT '0002b' FROM dual
8 )
9 SELECT a.id, b.id
10 FROM table_a a
11 LEFT OUTER JOIN table_b b ON a.id = substr(b.id, 1, 4);
ID ID
---- -----
0001 0001a
0002 0002b
0003