Sql 如何使用多连接转换旧Oracle(+;)

Sql 如何使用多连接转换旧Oracle(+;),sql,oracle,Sql,Oracle,我有使用旧的且不推荐的(+)符号的Oracle sql代码。我对如何转换有一个基本的了解,但我正在为多个表而挣扎 为埃克斯梅普 select [list of columns] from table1 t1, table2 t2, table3 t3, table4 t4, table5 t5 where t2.col1 = t1.col1 and t2.col2 = t3.col2 and t4.col1(+) = t2.col3 and t5.col1

我有使用旧的且不推荐的(+)符号的Oracle sql代码。我对如何转换有一个基本的了解,但我正在为多个表而挣扎

为埃克斯梅普

select [list of columns]
from table1 t1,
     table2 t2,
     table3 t3,
     table4 t4,
     table5 t5
where t2.col1 = t1.col1
and t2.col2 = t3.col2
and t4.col1(+) = t2.col3
and t5.col1(+) = t2.col4
and t5.col2(+) = t2.col5
希望这是有意义的。我相信这与其他类似的问题略有不同,因为它们没有在同一个查询中涵盖多个连接

t4.col1(+) = t2.col3
将转换为

RIGHT OUTER JOIN table2 t2 on t4.col1 = t2.col3
等等

但由于应首先将表2连接到表1,因此使用更常见的左连接和翻转表会更简洁:

from table1 t1,
INNER JOIN table2 t2 ON t2.col1 = t1.col1
LEFT JOIN table3 t3 ON t2.col2 = t3.col2
LEFT JOIN table4 t4 ON t2.col3 = t4.col1
LEFT JOIN table5 t5 ON t2.col4 = t5.col1
    and t2.col5 = t5.col2

只需将每个连接条件从
WHERE
子句移动到相应的
join

select [list of columns]
from   table1 t1
       join table2 t2
            on  t2.col1 = t1.col1
       join table3 t3
            on  t3.col2 = t2.col2
       left join table4 t4
            on  t4.col1 = t2.col3
       left join table5 t5
            on  t5.col1 = t2.col4
            and t5.col2 = t2.col5
我从不使用可选的(即冗余的)
内部
外部
关键字,或
右连接
(因为你总是可以将其反转,使其成为正常的
左连接
,避免很多混淆)。

呵呵,“可选”和“冗余”不是同义词。你似乎还暗示“不必要”——这是一个意见问题。无论何时,只要你能把你的意思说得非常清楚,你可能愿意也可能不愿意这样做。我愿意。不要留下混乱的空间!(例如,对于来自其他DB产品的人,可能需要这些关键字中的一个或另一个。)