Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Ignore insert into select duplicate key error

User_M7MRMJun 15 2017 — edited Jun 15 2017

Hi,

l would like to know if there is any way to continue insert into select after duplicate key error. meaning:  I would like to disregard the exception and to continue to insert the next record.

I'm familiar with ignore_row_on_dupkey_index but as far as I know, hints are should not be used in Production environment.

Few things:

1.  The query inserts millions of records into an empty table.

2.  I would prefer a good solution with a small effect on the performance.

Thanks,

Alex

An example of code that uses ignore_row_on_dupkey_index:

CREATE TABLE customers

( customer_id number(10) NOT NULL,

  customer_name varchar2(50) NOT NULL,

  city varchar2(50),

  CONSTRAINT customers_pk PRIMARY KEY (customer_id)

);

CREATE TABLE customers_2

( customer_id number(10) NOT NULL,

  customer_name varchar2(50) NOT NULL,

  city varchar2(50)

);

insert into customers_2 values(1,'A','TLV');

insert into customers_2 values(2,'B','TLV');

insert into customers_2 values(2,'C','TLV');

insert into customers_2 values(3,'C','TLV');

SELECT * FROM Customers_2

insert /*+ ignore_row_on_dupkey_index(customers, customers_pk) */

into customers select * from Customers_2

select * from Customers;

This post has been answered by Saubhik on Jun 15 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 13 2017
Added on Jun 15 2017
5 comments
2,983 views