關于Oracle的UPDATE更新多表的問題 有以下幾種方式可以實現: 一種是: update table1 set (field1,field2...) = (Select Field1,field2.... from table2 where table1.field1=table2.field1) where table1.field1 in (select field1 from table2)
二種是: 將table1,table2相關聯字段建立主鍵PRimary key 或Union key Update (Select Table1.field1,table1.field2,table2.field1,table2.field2 from table1,table2 where Table1.Field1=table2.field1)
Set table1.table2=table2.table2, table1.fieldn=table2.tablen, ...... table1的Field1和table2的field1將需要建立主鍵或唯一索引才行
三種是: merge into table1 using table2 on (table1.field1=table2.field1 and ....) when matched then Update set table1.field2=table2.field2, table1.fieldn=table2.fieldn, ...... when not matched then [doing other thing]