oracle association table update

If there is table A and table B, use in sql server:
update A set field2=b.filed2 from A,B where a.field1=b.field1 to get it done, so I am used to the SQL server update table statement, and then use oracle That's really awkward.
Scenario 1: If you only update the fixed value, the difference between oracle and sql server is not much:
update A set field2='OK'
where exists(select 1 from B where a.field1=b.field1)


Scenario 1: The update content is that
the grammar of the oracle update association table in the association table is a bit bloated.
update A set field2=(select b.field2 from B where a.field1=b.field1)
where exists(select 1 from B where a.field1=b.field1)
The value of the subquery can only be a unique value, not It is multi-valued.
In addition, oracle has also
changed the method and simplified it by view: update(select A.field2 as Afield2,B.field2 as Bfiled2 from A,B where A.field1=B.field1)
set Afield2=Bfield2

Scenario 3: The update content is multiple fields in the associated table

If you follow the grammar of scenario 2, would it be exhausting to
update multiple fields: update A set field3=(select b.field3,b.field4 from B where a.field1=b.field1),field4=(select b.field4 ,b.field4 from B where a.field1=b.field1)
where exists(select 1 from B where a.field1=b.field1)

Fortunately, there is the following simplified statement:
update A set (field3, field4)=(select b.field3,b.field4 from B where a.field1=b.field1)
where exists(select 1 from B where a.field1=b. field1)

Guess you like

Origin blog.csdn.net/xiaozaq/article/details/107854208