今天开发要更新一批数据,等了很久也没更新成功。找到了我,我在网上找了一下资料,发现在用rowid的方式更新最快,参照下面的文章更新成功,记录一下
DAVE文章链接:http://blog.csdn.net/tianlesoftware/article/details/6576156
原来的SQL:
update t_canhe_member_info a set a.id_card = (select b.id_card from BBB_EEE b where a.member_no = b.member_no) where a.join_year = ‘2014‘ ;批量更新的PL/SQL块:
DECLARE CURSOR cur IS SELECT a.id_card, b.ROWID ROW_ID FROM BBB_EEE a, t_canhe_member_info b WHERE a.member_no = b.member_no and b.join_year = ‘2014‘ ORDER BY b.ROWID; ---如果表的数据量不是很大,可以不用 order by rowid V_COUNTER NUMBER; V_JISHU number; --统计更新了多少条BEGIN V_COUNTER := 0; V_JISHU := 0; FOR row IN cur LOOP UPDATE t_canhe_member_info SET id_card = row.id_card WHERE ROWID = row.ROW_ID; V_COUNTER := V_COUNTER + 1; V_JISHU := V_JISHU + 1; IF (V_COUNTER >= 1000) THEN COMMIT; --1000条提交一次 V_COUNTER := 0; END IF; END LOOP; COMMIT; DBMS_OUTPUT.PUT_LINE(‘更新了 ‘ || V_JISHU || ‘条!‘ ); END;
时间: 2024-11-10 13:49:31