insert if not exists oracle

后端 未结 10 2097
天命终不由人
天命终不由人 2020-12-07 23:08

I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert.

10条回答
  •  佛祖请我去吃肉
    2020-12-07 23:37

    If you do NOT want to merge in from an other table, but rather insert new data... I came up with this. Is there perhaps a better way to do this?

    MERGE INTO TABLE1 a
        USING DUAL
        ON (a.C1_pk= 6)
    WHEN NOT MATCHED THEN
        INSERT(C1_pk, C2,C3,C4)
        VALUES (6, 1,0,1);
    

提交回复
热议问题