oracle批量更新資料

2021-06-19 21:13:04 字數 492 閱讀 2684

目的:兩個表t1,t2,t1裡面的字段,id,name,t2也是,將t2表和t1表裡面相等的id的記錄的name欄位更新到t1表裡面

1、

update t1 set (name) = (select t2.name from t2 where t2.id = t1.id) 

where exits (select 1 from t2 where t1.id = t2)

對於第二行,可能有的人可能不用,但是這會讓t1的所有記錄都會更新,在t2裡面有對應資料的時候正確更新,沒有對應資料的時候就是null

2、

update (select t1.id, t1.name tn1, t2.id, t2.name tn2 from t1, t2 where t1.id = t2.id)

set tn1 = tn2

前提條件是t2的id是主鍵

今天先寫到這裡

Oracle批量更新

需求 將t2 t statbuf 表中id和t1 t mt 表相同的記錄更新進t1表。1.錯誤的寫法 1update table name t1 set a,b,c select a,b,c from table name 2 t2 where t1.a t2.a 這種寫法,會更新t1表中的所有行 ...

oracle批量更新操作

專案問題是這樣的,有一張表tb user market使用者記錄繫結使用者,一開始沒有欄位system date,後來新加的,該欄位使用者記錄使用者繫結的時間 還有一張表tb log user market 裡面記錄的是使用者的繫結歷史資訊,可能有重複的使用者記錄,即使用者先繫結後解綁又繫結的情況,...

批量更新資料

update bs storage setstoreqty storeqty a.mqty from select nb disbill.companyid,goodsid,nb disbill.outstoreid,outstorepos,mqty,nb disbill.billno from n...