我想转换以下Oracle SQL查询语法(使用LEFT OUTER JOIN
而不是(+)
):
SELECT *
FROM TABLEA A, TABLEB B, TABLEC C, TABLED D
WHERE MY_COL = @col_val
AND A.X = B.X(+)
AND B.Y = C.Y(+)
AND D.Z=A.Z
这是我到目前为止所尝试的内容:
SELECT *
FROM TABLEA A, TABLEB B, TABLEC C, TABLED D
LEFT OUTER JOIN TABLEA A ON A.X = B.X
LEFT OUTER JOIN TABLEC C ON B.Y = C.Y
WHERE MY_COL = @col_val
AND D.Z = A.Z;
但我收到错误:
" ORA-00904:" B"。" X" :无效的标识符"
答案 0 :(得分:4)
join
上的D
是内联接,其余是左外连接:
SELECT *
FROM TABLEA A JOIN
TABLED D
ON D.Z = A.Z LEFT JOIN
TABLEB B
ON A.X = B.X LEFT JOIN
TABLEC C
ON B.Y = C.Y
WHERE MY_COL = @col_val;
我总是使用内部联接开始连接链,然后是left outer join
。我从不使用right join
和full join
。内部联接定义结果集中的行,因此它们首先出现。
答案 1 :(得分:1)
你不应该混合显性和隐性的sintax
SELECT *
FROM TABLEA A
INNER JOIN TABLEL L ON L.Z = A.Z
LEFT OUTER JOIN TABLEB B ON A.X = B.X
LEFT OUTER JOIN TABLEC C ON B.Y = C.Y
WHERE A.MY_COL = @col_val
你应该使用TABLEL的内连接(或连接)
答案 2 :(得分:0)
试试这个:
SELECT *
FROM TABLEA A
LEFT OUTER JOIN TABLEB B ON A.X = B.X
LEFT OUTER JOIN TABLEC C ON B.Y = C.Y
INNER JOIN TABLED D ON D.Z = A.Z
WHERE MY_COL = @col_val
TABLEB
和TABLEC
进入LEFT OUTER JOIN
(您使用了+),而TABLED
进入INNER JOIN