<p>In Oracle, given a simple data table:</p>

<pre><code>create table data (
    id       VARCHAR2(255),
    key      VARCHAR2(255),
    value    VARCHAR2(511));
</code></pre>

<p>suppose I want to "insert or update" a value. I have something like:</p>

<pre><code>merge into data using dual on 
    (id='someid' and key='testKey')
when matched then 
    update set value = 'someValue' 
when not matched then 
    insert (id, key, value) values ('someid', 'testKey', 'someValue');
</code></pre>

<p>Is there a better way than this? This command seems to have the following drawbacks:</p>

<ul>
<li>Every literal needs to be typed twice (or added twice via parameter setting)</li>
<li>The "using dual" syntax seems hacky</li>
</ul>

<p>If this is the best way, is there any way around having to set each parameter twice in JDBC?</p>

I would hide the MERGE inside a PL/SQL API and then call that via JDBC:
```
```
data_pkg.merge_data ('someid', 'testKey', 'someValue');
```
```
As an alternative to MERGE, the API could do:
```
```
begin
   insert into data (...) values (...);
exception
   when dup_val_on_index then
      update data
      set ...
      where ...;
end;
```
```