将sql server查询转换为oracle外连接问题

时间:2009-10-15 17:34:46

标签: sql-server oracle

我们在sql server中有以下查询:

SELECT  b.columnB, 
        b.displayed_name AS displayName, 
        c.type_cd, 
        c.type_desc, 
        b.month_desc AS month
FROM    table1 a, table2 b, table3 c
WHERE   b.region_code *= a.columnA
        AND c.program_type_cd *= a.program_type_cd

,在oracle中,转换为:

SELECT b.columnB,
       b.displayed_name displayName,
       c.type_cd,
       c.type_desc,
       b.month_desc month
FROM   table1 a,
       table2 b,
       table3 c
WHERE b.columnB = a.columnA(+)
       AND c.type_cd = a.type_cd(+)

但是在oracle中运行它时我们得到一个错误

"a table must be outer joined to at most one other table"

最好的解决方法是什么,并保持与sql server相同的逻辑?

2 个答案:

答案 0 :(得分:1)

尝试一次:

SELECT b.columnB,
       b.displayed_name displayName,
       c.type_cd,
       c.type_desc,
       b.month_desc month
FROM   table1 a
       LEFT JOIN table2 b ON b.columnB = a.columnA
       LEFT JOIN tablec c ON c.type_cd = a.type_cd

答案 1 :(得分:0)

如果你没有从中返回任何数据,为什么table1被列为OUTER JOIN?看起来你想让table1成为table2的内连接,然后在2和3之间做一个OUTER。像这样:

SELECT b.columnB,
       b.displayed_name displayName,
       c.type_cd,
       c.type_desc,
       b.month_desc month
FROM   table1 a,
       table2 b,
       table3 c
WHERE b.columnB = a.columnA
       AND c.type_cd = a.type_cd(+)

另一方面,我建议切换到ANSI连接(如Eric的例子) - 它们更容易阅读,虽然在功能上,它们是相同的,并且以完全相同的方式执行。

相关问题