如果表为空或using select不返回任何行,为什么此合并不运行insert语句?
MERGE INTO
`table` TGT
USING
(
SELECT
field
FROM
`table`
WHERE
field='1'
) SOURCE
ON
(TGT.field = SOURCE.field )
WHEN MATCHED THEN
UPDATE SET TGT.field='value1'
WHEN NOT MATCHED THEN
INSERT (field) VALUES ( 'value2')
答案 0 :(得分:1)
MERGE INTO
`table` DESTINY
USING
( select 'value' as Field) SOURCE
ON
DESTINY.Field = SOURCE.Field
WHEN MATCHED THEN UPDATE SET DESTINY.Field='value 1'
WHEN NOT MATCHED THEN INSERT (Field) VALUES ( 'value 2')