daniyal.bashir
daniyal.bashir

Reputation: 88

Oracle merge command error missing keyword

I am trying to merge two tables in oracle and the query i am using is

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);

Whenever I execute this query i get the following error:

ORA-00905 missing keyword.

Can anyone help me with this.

Upvotes: 0

Views: 897

Answers (1)

Lalit Kumar B
Lalit Kumar B

Reputation: 49122

 when matched 
      update set sh.amount = s.amount
 when not matched 
      insert (sh.prod,sh.month,sh.amount)

Your MERGE syntax is incorrect. You are missing the THEN keyword.

From the documentation:

merge_update_clause ::=

WHEN MATCHED THEN
   UPDATE SET ...

merge_insert_clause ::=

WHEN NOT MATCHED THEN
   INSERT

Upvotes: 2

Related Questions