Oracle Equivalent to MySQL INSERT IGNORE?

后端 未结 8 2367
旧时难觅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

    If you're on 11g you can use the hint IGNORE_ROW_ON_DUPKEY_INDEX:

    SQL> create table my_table(a number, constraint my_table_pk primary key (a));
    
    Table created.
    
    SQL> insert /*+ ignore_row_on_dupkey_index(my_table, my_table_pk) */
      2  into my_table
      3  select 1 from dual
      4  union all
      5  select 1 from dual;
    
    1 row created.
    

提交回复
热议问题