【问题标题】:Oracle merge command error missing keywordoracle合并命令错误缺少关键字
【发布时间】:2016-02-11 00:23:55
【问题描述】:

我正在尝试在 oracle 中合并两个表,我使用的查询是

merge into sales_history sh
 using sales s
 on (s.prod=sh.prod and s.month=sh.month)
 when matched 
      update set sh.amount = s.amount
 when not matched 
      insert (sh.prod,sh.month,sh.amount)
      values (s.prod,s.month,s.amount);

每当我执行此查询时,我都会收到以下错误:

ORA-00905 缺少关键字。

谁能帮帮我。

【问题讨论】:

  • when matched THEN update .... when not matched THEN ...
  • 是的,我发现了错误,但非常感谢您的回答:)

标签: sql oracle sql-merge ora-00905


【解决方案1】:
 when matched 
      update set sh.amount = s.amount
 when not matched 
      insert (sh.prod,sh.month,sh.amount)

您的 MERGE 语法不正确。您缺少 THEN 关键字。

来自documentation

merge_update_clause ::=

WHEN MATCHED THEN
   UPDATE SET ...

merge_insert_clause ::=

WHEN NOT MATCHED THEN
   INSERT

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-23
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多