insert if not exists oracle

后端 未结 10 2084
天命终不由人
天命终不由人 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:40

    This only inserts if the item to be inserted is not already present.

    Works the same as:

    if not exists (...) insert ... 
    

    in T-SQL

    insert into destination (DESTINATIONABBREV) 
      select 'xyz' from dual 
      left outer join destination d on d.destinationabbrev = 'xyz' 
      where d.destinationid is null;
    

    may not be pretty, but it's handy :)

提交回复
热议问题