Oracle Equivalent to MySQL INSERT IGNORE?

后端 未结 8 2348
旧时难觅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条回答
  •  -上瘾入骨i
    2020-11-27 07:55

    Another variant

    Insert into my_table (student_id, group_id)
    select distinct p.studentid, g.groupid 
    from person p, group g
    where NOT EXISTS (select 1
                     from my_table a
                     where a.student_id = p.studentid
                     and a.group_id = g.groupid)
    

    or you could do

    Insert into my_table (student_id, group_id)
    select distinct p.studentid, g.groupid 
    from person p, group g
    MINUS
    select student_id, group_id
    from my_table 
    

提交回复
热议问题