2015-11-10 88 views
0

我想在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 missing keyword.

谁能帮我这个。

+0

'匹配时THEN更新....当THEN不匹配...' –

+0

是的,我发现了错误,但非常感谢你答复环:) –

回答

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