Oracle merge constants into single table

后端 未结 3 1548
攒了一身酷
攒了一身酷 2021-02-01 06:25

In Oracle, given a simple data table:

create table data (
    id       VARCHAR2(255),
    key      VARCHAR2(255),
    value    VARCHAR2(511));

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-01 06:50

    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;
    

提交回复
热议问题