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!

Updating a table from source - duplicate records exist in source

665881Oct 17 2008 — edited Oct 20 2008
Hi All

I need logic to know how to update a target table from source. here the issue is source table contains duplicate data.
Oracle version is 10.2.0.3.0
OS - Sun Solaris

Target Table - Fields A,B and C. A and B are primary keys.

A B C
1 1
1 2
2 2
2 1

Source Table - No primary keys.

A B C
1 1 2
1 1 2
1 1 3
2 1 4

Based on fields A and B, column C needs to be updated from source table.

In the target table, 4th row should get updated to value 4.
In the target table - For first row, from source table, first 3 rows are matching. i am fine with any values (2,2,3).
In the target table - for second and third row, value of c should be null.
Currently I am updating this one through cursor. but it is taking lot of time.
In the production, less than one percent of records are duplicate records. I was asked to update the good records with regular update statement and duplicate records with cursor or some other logic. hence less than one percent records will be looped to cursor. basically management want to reduce load on cursor.

Your help is most appreciated.

Thanks
This post has been answered by SomeoneElse on Oct 18 2008
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 17 2008
Added on Oct 17 2008
5 comments
1,434 views