朋友我正在使用合并语法更新并在表中插入值
MERGE INTO iq_dnr b
USING (SELECT *
FROM iq_dnr
WHERE co_series = 'IO' AND CATEGORY = 9 AND dnr_from = 13567362) a
ON ( a.co_series = b.co_series
AND a.CATEGORY = b.CATEGORY
AND a.dnr_from = b.dnr_from)
WHEN MATCHED THEN
UPDATE
SET b.dnr_to = 0001
WHEN NOT MATCHED THEN
INSERT (co_series, CATEGORY, dnr_from, dnr_to)
VALUES ('IO', 9, 13567362, 00001)
我想询问是否可以像在上面的查询中一样检查并插入一个表中。 知道问题是我能够成功更新表但我无法插入值。 plss帮帮我
答案 0 :(得分:3)
尝试使用DUAL,它可能会解决您的问题:
MERGE INTO iq_dnr b
USING (SELECT 'IO' co_series,
9 CATEGORY,
13567362 dnr_from
FROM dual) a
ON ( a.co_series = b.co_series
AND a.CATEGORY = b.CATEGORY
AND a.dnr_from = b.dnr_from)
WHEN MATCHED THEN
UPDATE
SET b.dnr_to = 0001
WHEN NOT MATCHED THEN
INSERT (co_series, CATEGORY, dnr_from, dnr_to)
VALUES ('IO', 9, 13567362, 00001)
使用上面的DUAL
可以确保它返回一些能让MERGE语句保持工作的东西......