Oracle Merge vs Select then Insert or Update
Posted
by
DRTauli
on Stack Overflow
See other posts from Stack Overflow
or by DRTauli
Published on 2012-09-05T03:35:35Z
Indexed on
2012/09/05
3:37 UTC
Read the original article
Hit count: 156
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'
© Stack Overflow or respective owner