听人说forall可以提高游标的性能,哪位大侠知道怎么使用啊,给个例子看看好吗?

解决方案 »

  1.   

    --create table t_test1 as select table_name,owner from dba_tables where 0=1;
    set serveroutput on size 100000
    set timing on
    declare
      type typ1 IS TABLE OF t_test1%ROWTYPE INDEX BY BINARY_INTEGER;
      rec_tab typ1;
      CURSOR c1 IS SELECT table_name, owner from dba_tables;
      i number;
      j number;
      k number;
    begin
      OPEN c1;
      loop
        FETCH c1 BULK COLLECT INTO rec_tab LIMIT 2699;
        i := c1%ROWCOUNT;
        exit when not rec_tab.EXISTS(1);
        dbms_output.put_line('fetch '||i||' rows');
        forall j in rec_tab.FIRST..rec_tab.LAST
          insert into t_test1 values rec_tab(j);
        k := SQL%ROWCOUNT;
        dbms_output.put_line('insert '||k||' rows');
        commit;
        exit when c1%notfound;
      end loop;
      close c1;
    end;
    /