批量更新資料問題

2022-03-20 12:54:47 字數 753 閱讀 4746

同事最近遇到乙個需要根據索引字段更新狀態資料的需求,而這個處理邏輯是迴圈查詢單條更新解決

主要**如下(簡寫):

<?php 

foreach($array

as$v

)?>

主體思想是迴圈陣列,進行更新,這樣的話就是要一條條的update,這樣資料多了以後總感覺執行過於緩慢,會給資料庫帶來壓力,於是我查了查資料,找到了乙個批量更新

例子如下:

這是乙個簡單的例子,採用 case when then end的語句完成sql更新裡面的if else

降低update執行的頻次,能夠做到每50條一更新 或者每 100條一更新,這樣就能大幅度的降低執行時間,減少資料庫的壓力了。

原sql如下:

update `test_user` set num=

case

`name`

when

'test1

'then

'100

'when

'test2

'then

'200

'when

'test3

'then

'300

'end

where name in ("test1","test2","test3");

PLSQL 批量更新資料效率問題

最近做報表專案遇到乙個棘手問題,需要把舊系統的30w條資料更新到oracle資料庫中,舊系統的資料儲存在excel裡面,結構如下 vipno sssssss1aa aaa2 bbbb 資料庫的表t結構類似,但是我需要根據excel裡面的vipno更新新oracle資料庫sss 和 ssss列。其中t...

批量更新資料

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

oracle批量更新資料

目的 兩個表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 ...