Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update query in oracle

Status
Not open for further replies.

goodfriend

Programmer
Sep 25, 2003
3
US
I have the following problem:
There are 2 tables which are identical COLA being primary key:-

Table A Table B
---------------- ----------------
COLA COLB COLC COLA COLB COLC
1 ABC XYZ 1 ABC XYZ
2 PQR DEF 2 RPQ FDE

Except that Table A has Changed information which I need to
Sync with Table B at the end of the Day.

I am trying to use SQL to solve the above problem.

IS there anyway in Oracle to execute one SQL and acheive the above, I am aware that finally I can delete the record and reinsert it, however, I would like to do it using a update statement.

I have tried the following without success:
UPDATE B set (COLB, COLC) = ( select COLB, COLC from A where B.COLA = A.COLA )
The above query updates all the rows in table B >:-<

Thanks for all your help.
 
this operation could be a bit complex:

update
(select table_a.colc c1, table_b.colc c2 from Table_A,
Table_B where table_a.cola = table_bcola) x
set c2 = c1

update
(select table_a.colc c1, table_b.colc c2 from Table_A,
Table_B where table_a.cola = table_b.cola) x
set c2 = c1

insert into table_b
(select * from table_a where not cola in (select cola from tableb))

delete from table_b
where not cola in(select cola from table_a)

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
UPDATE B set (COLB, COLC) = ( select COLB, COLC from A where B.COLA = A.COLA
AND (b.COLB <> A.COLB OR b.COLC <> A.COLC)
)
 
UPDATE B
set (COLB, COLC) = (select COLB, COLC
from A
where B.COLA = A.COLA )
where b.cola = (select a.cola
from a
where a.COLA = b.COLA )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top