Oracle游标分批循环处理总结

此处理方式适用于数据量巨大的循环处理方面,能有效提循环处理效率,具体语句块示例如下所示:

DECLARE
    CURSOR cur IS
      SELECT * FROM t_table;
    TYPE rec IS TABLE OF t_table%ROWTYPE;
    recs rec;
  BEGIN
    OPEN cur;
    WHILE (TRUE) LOOP
      FETCH cur BULK COLLECT
        INTO recs LIMIT 100;
      FORALL i IN 1 .. recs.COUNT
        INSERT INTO t_table VALUES recs (i);
      COMMIT;
      EXIT WHEN cur%NOTFOUND;
    END LOOP;
    CLOSE cur;
  END;
  /

你可能感兴趣的:(个人博客,Oracle)