title: Oracle Merge vs Select then Insert or Update
body: <p>What is faster?</p>
  
  <p>the Merge statement</p>
  
  <pre><code>    MERGE INTO table_name 
       USING dual
       ON (row_id = 'some_id')
      WHEN MATCHED THEN
       UPDATE SET col_name = 'some_val'
      WHEN NOT MATCHED THEN
       INSERT (row_id, col_name)
       VALUES ('some_id', 'some_val')
  </code></pre>
  
  <p>or </p>
  
  <p>querying a select statement then using an update or insert statement.</p>
  
  <pre><code>    SELECT * FROM table_name where row_id = 'some_id'
  </code></pre>
  
  <p>if rowCount == 0</p>
  
  <pre><code>    INSERT INTO table_name (row_id,col_name) VALUES ('some_id','some_val')
  </code></pre>
  
  <p>else</p>
  
  <pre><code>    UPDATE table_name SET col_name='some_val' WHERE row_id='some_id'
  </code></pre>