1

quite the same question as here : Copy data from one existing row to another existing row in SQL?

but in Oracle, where update ... from and update t1, t2 are not supported.

I'll repeat it here in my own words ; I have a table T, which looks like this :

table

and as the arrow shows it, I want to copy everything from r where c = 1 to e where c = 2, with t matching.

I have the select statement to get what I want to copy :

select 
  told.t, 
  told.r
from 
  T told 
  inner join 
  T tnew
on 
  told.t= tnew.t
where 
  told.c = 1
  and 
  tnew.c = 2

I just don't know how to put this together in an update. An Oracle update, specifically.

2 Answers 2

4

try this:

update T tnew
set tnew.e = (select told.r from T told where told.c = 2 and told.t = tnew.t)
where tnew.c = 1
Sign up to request clarification or add additional context in comments.

1 Comment

Well... thanks. It seems a lot easier now that I know the answer !
0

Sounds like the time for a bulk collects! Not as pretty as AB Cade's solution but more efficient.

declare

  c_data is
   select t1.rowid as rid, t2.r
     from my_table t1
     join my_table t2
       on t1.t = t2.t
    where t1.c = 2
      and t2.c = 1
          ;

   type t__data is table of c_data index by binary_integer;
   t_data t__data;

begin

   open c_data;
   loop

      fetch c_data bulk collect into t_data limit 25000;

      exit when t_data.count = 0;

      forall i in t_data.first .. t_data.last loop
         update my_table
            set e = t_data(i).r
          where rowid = t_data(i).rid
                ;

      commit;

   end loop;
   close c_data;

end;
/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.