Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle DB equivalent of on duplicate key update

Tags:

sql

oracle

I need to execute the following MySQL-query in Oracle:

INSERT INTO users VALUES(1,10) ON DUPLICATE KEY UPDATE points = 10;

Is there something else besides merge? I just don't understand it.

like image 986
Evgenij Reznik Avatar asked May 14 '12 18:05

Evgenij Reznik


1 Answers

If you don't want to use MERGE, you can try:

begin
   INSERT INTO users VALUES(1,10);

   exception
      when dup_val_on_index then
         update users
            set points = 10
          where id = 1;
end;
like image 74
archimede Avatar answered Oct 12 '22 12:10

archimede