Unix Technical Forum

Update one table's data from another table (but skip identical records)

This is a discussion on Update one table's data from another table (but skip identical records) within the Oracle Miscellaneous forums, part of the Oracle Database category; --> I'm looking for a way to update data in one table with data from another table. More specifically, if ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 12:17 PM
gordon@panix.com
 
Posts: n/a
Default Update one table's data from another table (but skip identical records)

I'm looking for a way to update data in one table with data from
another table.

More specifically, if there are any records in the two tables which
have matching primary keys but differing data in at least one other
column, I need to update the values in the old table from the new
table.

I can't just do a blanket update of every record, because that would
result in a lot of unneccesary updates -- I only want to update
records which actually have different data.

I tried an UPDATE FROM statement, but Oracle doesn't support that.

I tried a MERGE INTO statement, but Oracle 9i requires action to be
taken both when the records match *and* when they don't. Bah!

Any suggestions?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 12:17 PM
DA Morgan
 
Posts: n/a
Default Re: Update one table's data from another table (but skip identicalrecords)

gordon@panix.com wrote:
> I'm looking for a way to update data in one table with data from
> another table.
>
> More specifically, if there are any records in the two tables which
> have matching primary keys but differing data in at least one other
> column, I need to update the values in the old table from the new
> table.
>
> I can't just do a blanket update of every record, because that would
> result in a lot of unneccesary updates -- I only want to update
> records which actually have different data.
>
> I tried an UPDATE FROM statement, but Oracle doesn't support that.
>
> I tried a MERGE INTO statement, but Oracle 9i requires action to be
> taken both when the records match *and* when they don't. Bah!
>
> Any suggestions?


And a correlated update won't work? Why?
http://www.psoug.org
click on Morgan's Library
click on UPDATE
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 12:17 PM
gordon@panix.com
 
Posts: n/a
Default Re: Update one table's data from another table (but skip identical records)

Thanks! I'll give that a try.

Can a correlated update operate on more than one field at a time? And
if not, would updating each field in a record result in several
separate updates? I have a trigger that fires on updates, and it would
be really nice to have just one trigger activation per record, even if
that record has several fields to update.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 12:17 PM
gordon@panix.com
 
Posts: n/a
Default Re: Update one table's data from another table (but skip identical records)

Oops, now I see the multi-column update example. I'll give that a
shot.

Thanks again.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:29 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com