【问题标题】:oracle DELETE records while MERGEoracle DELETE 记录同时合并
【发布时间】:2014-03-14 09:42:49
【问题描述】:

我将记录从newtest 合并到test

merge into test t
using newtest nt
on (t.id = nt.id)
when matched then
  update
     set t.name = nt.name
when not matched then
  insert (id, name)values (nt.id, nt.name); 

newtest中符合on条件的记录需要删除。

虽然我可以用delete SQL 做到这一点,但我想知道它可以在那个 MERGE 语句中完成吗?

【问题讨论】:

  • 做不到。 MERGE 只能修改MERGE INTO 子句后列出的表,不能修改USING 子句后的表。

标签: sql oracle merge


【解决方案1】:

正如 kordiko 澄清的那样,您不能使用 MERGE 语句从另一个表中删除。您可以在单独的语句中完成删除,如下所示:

DELETE FROM newtest nt
WHERE NOT EXISTS
(SELECT 1 FROM test t where t.id = nt.id);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-12
    • 2013-01-02
    • 2016-11-07
    • 1970-01-01
    • 1970-01-01
    • 2012-02-01
    • 1970-01-01
    相关资源
    最近更新 更多