Oracle Merge vs Select then Insert or Update
- by DRTauli
What is faster?
the Merge statement
MERGE INTO table
USING dual
ON (rowid = 'some_id')
WHEN MATCHED THEN
UPDATE SET colname = 'some_val'
WHEN NOT MATCHED THEN
INSERT (rowid, colname)
VALUES ('some_id', 'some_val')
or
querying a select statement then using an update or insert statement.
SELECT * FROM table where rowid = 'some_id'
if rowCount == 0
INSERT INTO table (rowid,colname) VALUES ('some_id','some_val')
else
UPDATE table SET colname='some_val' WHERE rowid='some_id'