1

我对这个查询有疑问:

  MERGE INTO qot
  USING dual
  ON (qot_id = 1023125885)
  WHEN MATCHED AND qot_exc_id = 4 THEN UPDATE SET qot_exc_id = 259
  WHEN MATCHED AND qot_exc_id = 6 THEN UPDATE SET qot_exc_id = 131;

我收到一个错误:“缺少关键字”。有人可以给我任何线索吗?

谢谢!

问候,

河。

4

1 回答 1

4

我不知道为什么您只想更新而不是插入时尝试使用 MERGE。您不能像现在这样在 WHEN 子句中添加条件 - 请参阅文档

为什么不这样做:

update qot
set qot_exc_id = case qot_exc_id
                    when 4 then 259
                    when 6 then 131
                    end
where qot_id = 1023125885
and qot_exc_id in (4,6);

如果你真的需要一个 MERGE 那么你想要这样的东西:

MERGE INTO qot
USING dual
ON (qot_id = 1023125885)
WHEN MATCHED THEN 
  UPDATE SET qot_exc_id = case qot_exc_id
                            when 4 then 259
                            when 6 then 131
                            else qot_exc_id
                            end;

也许:

MERGE INTO qot
USING dual
ON (qot_id = 1023125885 and qot_exc_id in (4,6))
WHEN MATCHED THEN 
  UPDATE SET qot_exc_id = case qot_exc_id
                            when 4 then 259
                            when 6 then 131
                            end;
于 2012-07-04T09:06:16.557 回答