Hi,

I'm on DIGEST, so I don't know if that's
been answered already, or not.

But anyhow, what about:

update (
select t.field1 f, t.field2 v, d.field1 g, d.field2 w from
testtable1 t, testtable2 d
where t.id = d.id)
set f = g, v = w

HTH

Dieter Buecherl

> From: "Eric D. Pierce" <[EMAIL PROTECTED]>
> Date: Wed, 30 May 2001 13:02:14 -0700
> Subject: Re: Update Query
>
>ha, ha. you got bit by the "null" update thing too, I remember it 
>well! :)
>
>except for maybe some newfangled oracle8 features, the "ugly" one is 
>the "traditional" way the manual says to do it (iirc). I have many 
>many scripts with that kind of code in them since we load mainframe 
>datafiles into the local oracle apps, and do a lot of cross-table 
>updates  (non-normalized, but that is mostly ok since it is archive 
>data).
>
>you *can* "pretty" it up a bit by using better formatting,
>e.g.,
>
>
>update 
>       tablea a
>   set 
>     ( 
>       a.firstname,
>       a.lastname
>     )
>   = 
>     ( 
>       select 
>              b.firstname,
>              b.lastname 
>         from 
>              tableb b
>        where 
>              b.id = a.id 
>     )
> where 
>       a.id in
>     (
>       select 
>              b2.id
>         from 
>              tableb b2
>      )
>/
>
>
>On 30 May 2001, at 11:56, CC Harvest wrote:
>
>Date sent:             Wed, 30 May 2001 11:56:14 -0800
>To:                    Multiple recipients of list ORACLE-L
<[EMAIL PROTECTED]>
>
>> Seems like Oracle Doesn't have to the query like this:
>> 
>> update tablea set firstname=tableb.firstname,
>> lastname=tableb.lastname
>> where tableb.id = tablea.id;
>> 
>> I can have one, it works if it has a match for the two
>> tables, otherwise the two columns updated to null:
>> 
>> update tablea set (firstname,lastname)
>> =(select firstname,lastname from tableb
>>   where tableb.id=tablea.id);
>> 
>> Then the following one works, but very ugly:
>> 
>> update tablea set (firstname,lastname)
>> =(select firstname,lastname from tableb
>>   where tableb.id=tablea.id)
>> where exists(
>> select 'x' from tableb 
>>   where tableb.id=tablea.id)
>
>...
>
>
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Buecherl Dieter (BUE)
  INET: [EMAIL PROTECTED]

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).

Reply via email to