Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Updating a column's contents to the contents of another table's column, where both tables are linked by an ID
How do you update a column's contents to the contents of another table's column, where both tables are linked by an ID?
E.g.:
TABLE1.ID
TABLE1.COLOR
TABLE2.ID
TABLE2.COLOR
and I want to set TABLE1.COLOR to be the same value as TABLE2.COLOR
whenever TABLE1.ID = TABLE2.ID?
I realize that in many or all cases this will mean the data is not normalized, but is there another way (e.g., using just SQL) to do this besides the following PL/SQL code:
CURSOR TABLE2_COLORS_CUR IS
SELECT T1.ROWID, T2.*
FROM TABLE1 T1, TABLE2 T2
WHERE T1.ID = T2.ID;
FOR rec IN TABLE2_COLORS_CUR
LOOP
update TABLE1
set COLOR = rec.COLOR where rowid=REC.rowid
![]() |
![]() |