Wednesday, January 7, 2009

PL/SQL : How to update using select

This "problem" came across me when I needed to update an entire temporary table column. One option is to loop all table rows, boring and time consumer task. After some background searchs I've adopted this method:

UPDATE TABLEA SET
(TABLEA.COLUMNA, TABLEA.COLUMNB) =
(SELECT TABLEB.COLUMNA, TABLEB.COLUMNB FROM TABLEB WHERE TABLEB.ID = TABLEA.ID)

I've basically do one inner select and join the two tables in the inner select's WHERE clause.

No comments:

All Rights Reserved