I need to execute the following MySQL-query in Oracle:
INSERT INTO users VALUES(1,10) ON DUPLICATE KEY UPDATE points = 10;
Is there somethi
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;
MERGE INTO users u
USING (SELECT 1 as id FROM dual) a
ON a.id = u.id
WHEN MATCHED THEN UPDATE SET u.points = 10
WHEN NOT MATCHED THEN INSERT (id, points) VALUES (1, 10);
You would need to use a MERGE
. Something like
MERGE INTO users dest
USING( SELECT 1 user_id, 10 points FROM dual) src
ON( dest.user_id = src.user_id )
WHEN MATCHED THEN
UPDATE SET points = src.points
WHEN NOT MATCHED THEN
INSERT( user_id, points )
VALUES( src.user_id, src.points );