Oracle merge constants into single table

后端 未结 3 1555
攒了一身酷
攒了一身酷 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:57

    I prefer to try the update before the insert to save having to check for an exception.

    update data set ...=... where ...=...;
    
    if sql%notfound then
    
        insert into data (...) values (...);
    
    end if;
    

    Even now we have the merge statement, I still tend to do single-row updates this way - just seems more a more natural syntax. Of course, merge really comes into its own when dealing with larger data sets.

提交回复
热议问题