title: Oracle merge instead of insert?
body: <p>I currently have an insert statement in a perl script using the <code>DBI</code> module that collects router interface data. It works each time, but obviously with Unique constraint error because some items exist when the script is re-run. I am trying to do a merge instead, but I am unsure of how to do it by not selecting data from another table like the examples I have seen. To better understand, the perl script collects data by running <code>ssh</code> to the devices and stores certain information into variables. for instance interface name will be <code>$interface</code>. etc.</p>
  
  <p>The current insert statement</p>
  
  <pre><code>$dbh-&gt;do("INSERT INTO table VALUES (?, ?, ?, ?, ?)", undef, $interface, $id, $device, $description, $user);
  </code></pre>
  
  <p>I started writing the merge funtion, but I cannot seem to grasp how this will work, as all the merge statements do select from other tables and matching data and then do update/insert? The below example selects data from from 2 different tables and matching, however I am only looking at one table and want to merge new data.</p>
  
  <pre><code>MERGE INTO bonuses D
     USING (SELECT employee_id, salary, department_id FROM employees
     WHERE department_id = 80) S
     ON (D.employee_id = S.employee_id)
     WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01
       DELETE WHERE (S.salary &gt; 8000)
     WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
   VALUES (S.employee_id, S.salary*.01)
   WHERE (S.salary &lt;= 8000); 
  </code></pre>
  
  <p>So it is merging data into <code>bonuses</code> but matching it from employees. Even if such a statement would have worked, is it even possible using such a statement in a perl script?</p>