1. 程式人生 > >oracle資料庫資料量較大時更新資料較慢問題

oracle資料庫資料量較大時更新資料較慢問題

           這今天在研究kettle工具,是一款國外純java開發的開源ETL工具,抽取資料確實非常方便,大家有空可以去下載下來試試看,方便之處在於它不用安裝,解壓完了就能直接用了(必須提前配置jdk和jre環境到系統環境中)。今天要說的不是這款軟體,問題是由使用這個軟體引起的,我在抽取資料後需要完成一個更新操作語句如下:

update case_person_saxx a set a.case_id=(select id from case_xzcf b where b.app_id = a.app_id) ;

update invole_case_unit_saxx a set a.case_id=(select id from case_xzcf b where b.app_id = a.app_id);

 上面的語句中case_person_saxx表和case_xzcf 表中資料量大概在16萬條左右,說起來也不是特別大,但是這個語句執行起來特別的慢,我等了半個多小時都沒執行完,後來建索引稍微快一點,在網上找到一種更快捷的更新語句(因為我資料庫基礎不好很多語句不熟悉,呵呵!大神來看到了別笑話我就行!)如下:

merge into case_person_saxx t
using (select max(id) as id, app_id from case_xzcf group by app_id) s
on (t.app_id = s.app_id)
when matched then
  update set t.case_id = s.id;


  merge into invole_case_unit_saxx t
using (select max(id) as id, app_id from case_xzcf group by app_id) s
on (t.app_id = s.app_id)
when matched then
  update set t.case_id = s.id;

測試了一下 7秒鐘就完成了更新,瞬間讓我覺得自己懂得太少,真心需要好好學習。

記下來以便自己以後查閱,如果有同樣困擾的同學可以試試這個語句。