标签:oracle
采用存储过程的方式批量更新数据,Oracle中也可采用merge-update的方式更新,不过采用如下存储过程的方式会更快些
DECLARE MAX_ROWS NUMBER DEFAULT 5000; ROW_ID_TABLE DBMS_SQL.UROWID_TABLE; DATE_TIME_TABLE DBMS_SQL.DATE_TABLE; CURSOR C1 IS SELECT /*+ use_hash(t1,t2) parallel(t1,2) parallel(t2,2) */ T1.DATE_TIME, T2.ROWID FROM TEST_TABLE_1 T1, TEST_TABLE_2 T2 WHERE T1.TABLE_ID = T2.TABLE_ID AND T2.DATE_TIME IS NULL AND T1.DATE_TIME IS NOT NULL ORDER BY T2.ROWID; BEGIN OPEN C1; LOOP EXIT WHEN C1%NOTFOUND; FETCH C1 BULK COLLECT INTO DATE_TIME_TABLE, ROW_ID_TABLE LIMIT MAX_ROWS; FORALL I IN 1 .. ROW_ID_TABLE.COUNT UPDATE TEST_TABLE_2 SET DATE_TIME = DATE_TIME_TABLE(I), LCD=SYSDATE WHERE ROWID = ROW_ID_TABLE(I); COMMIT; END LOOP; CLOSE C1; END; /
本文出自 “脚踏实地,仰望星空” 博客,请务必保留此出处http://xubcing.blog.51cto.com/3502962/1619423
标签:oracle
原文地址:http://xubcing.blog.51cto.com/3502962/1619423