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!

Update logic

cubeguySep 7 2021 — edited Sep 7 2021

Version 11.2.4
create table t1 (id number ,c1 varchar2(10),c2 varchar2(10),c3 varchar2(10),c4 varchar2(10),c5 varchar2(10),c6 varchar2(10),c7 varchar2(10),c8 varchar2(10),c9 varchar2(10),c10 varchar2(10));

insert into t1 values (100,'T11','T12','T13','T14','T15','T16','T17','T18','T19','T110');

create table t2 (oid number,c1 varchar2(10),c2 varchar2(10),c3 varchar2(10),c4 varchar2(10),c5 varchar2(10),c6 varchar2(10),c7 varchar2(10),c8 varchar2(10),c9 varchar2(10),c10 varchar2(10));

insert into t1 values (1,'T21','T22','T23',null,null,'T26','T27',null,'T29','T210');

I want to update table t1 using t2.

Logic is :
update t1 set c1 = (select c1 from t2 where oid =1 and c1 is not null) and id = 100;
update t1 set c2 = (select c2 from t2 where oid =1 and c2 is not null) and id = 100;
update t1 set c3 = (select c3 from t2 where oid =1 and c3 is not null) and id = 100;
update t1 set c4 = (select c4 from t2 where oid =1 and c4 is not null) and id = 100;
update t1 set c5 = (select c5 from t2 where oid =1 and c5 is not null) and id = 100;
update t1 set c6 = (select c6 from t2 where oid =1 and c6 is not null) and id = 100;
update t1 set c7 = (select c7 from t2 where oid =1 and c7 is not null) and id = 100;
update t1 set c8 = (select c8 from t2 where oid =1 and c8 is not null) and id = 100;
update t1 set c9 = (select c9 from t2 where oid =1 and c9 is not null) and id = 100;
update t1 set c10 = (select c10 from t2 where oid =1 and c10 is not null) and id = 100;

I need above all update statements to a single update statement

This post has been answered by Solomon Yakobson on Sep 7 2021
Jump to Answer
Comments
Post Details
Added on Sep 7 2021
6 comments
165 views