Oracle Equivalent to MySQL INSERT IGNORE?

后端 未结 8 2352
旧时难觅i
旧时难觅i 2020-11-27 07:24

I need to update a query so that it checks that a duplicate entry does not exist before insertion. In MySQL I can just use INSERT IGNORE so that if a duplicate record is fo

8条回答
  •  一整个雨季
    2020-11-27 07:37

    I don't think there is but to save time you can attempt the insert and ignore the inevitable error:

    begin
    
       insert into table_a( col1, col2, col3 )
       values ( 1, 2, 3 );
    
       exception when dup_val_on_index then 
          null;
    
    end;
    /
    

    This will only ignore exceptions raised specifically by duplicate primary key or unique key constraints; everything else will be raised as normal.

    If you don't want to do this then you have to select from the table first, which isn't really that efficient.

提交回复
热议问题