I’m relatively new to Oracle, having working on MS SQL for most of my career. I’m used to doing stuff like:
update t
set Col1 = o.Col2
from MyTable t
join OtherTable o on t.OtherID = o.ID
I tried this syntax in Oracle, and it doesn’t accept it. Looked in Oracle docs and couldn’t find an example of what I’m trying to do.
How do you do it?
Option A) A correlated subquery
This requires that the subquery return no more than 1 match for each row in the table being updated. If it returns no match, the column will be updated with
NULL, which may not be what you want. You could addWHERE EXISTS (SELECT o.col2 FROM OtherTable o WHERE t.OtherID = o.ID)to cause the update to only occur where a match is found.Option B) Updating a join view
This is closer to what you are used to doing. It will only work if Oracle can determine a unique row in the underlying table for each row in the join — which I think basically means that
IDmust be a unique key ofotherTable.