我正在寻找一个SELECT-JOIN语句,该语句可以精确地重现MERGE语句,以便可视化SOURCE表和TARGET表之间完成的精确匹配。
以其他方式,JOIN是哪种? 完全加入?全部加入?内部联接?依此类推。
谢谢。
答案 0 :(得分:1)
发表声明:
FULL OUTER JOIN
这可能是SELECT COALESCE( dst.some_columns, src.some_columns ) AS some_columns,
NVL2( dst.some_columns, dst.columns_to_update_from, columns_to_update )
AS columns_to_update
FROM source src
FULL OUTER JOIN destination dst
ON ( dst.some_columns = src.some_columns )
:
LEFT OUTER JOIN
也可以是UNION
和-- WHEN MATCHED OR WHEN NOT MATCHED IN DESTINATION
SELECT src.some_columns,
NVL2( dst.some_columns, dst.columns_to_update_from, columns_to_update )
AS columns_to_update
FROM source src
LEFT OUTER JOIN destination dst
ON ( dst.some_columns = src.some_columns )
UNION ALL
-- WHEN NOT MATCHED IN SOURCE
SELECT some_columns,
columns_to_update_from
FROM destination dst
WHERE NOT EXISTS ( SELECT 1
FROM source src
WHERE ( dst.some_columns = src.some_columns ) )
:
INNER JOIN
也可以是UNION
和-- WHEN MATCHED
SELECT src.some_columns,
dst.columns_to_update_from AS columns_to_update
FROM source src
INNER JOIN destination dst
ON ( dst.some_columns = src.some_columns )
UNION ALL
-- WHEN NOT MATCHED IN DESTINATION
SELECT some_columns,
columns_to_update
FROM source src
WHERE NOT EXISTS ( SELECT 1
FROM destination dst
WHERE ( dst.some_columns = src.some_columns ) )
UNION ALL
-- WHEN NOT MATCHED IN SOURCE
SELECT some_columns,
columns_to_update_from
FROM destination dst
WHERE NOT EXISTS ( SELECT 1
FROM source src
WHERE ( dst.some_columns = src.some_columns ) )
:
foreach ($_items as $_item):
echo "<pre>";
var_dump($_item->debug());
echo "</pre>";