批量收集程序长时间运行

时间:2018-07-13 06:22:36

标签: oracle plsql procedure

我在使用批量收集时遇到问题,我的表仅包含10000条记录,您能帮助我找到我的程序做错了吗。

DECLARE
   ctr        NUMBER;
   str        CLOB;

   CURSOR s_cur
   IS
      SELECT                                                /* +parallel(8) */
            * FROM tmp_billinfo;

   CURSOR s_cur2 (var1 VARCHAR2)
   IS
      SELECT                                                /* +parallel(8) */
            TO_CHAR (poid_id0) poid_id0, poid_type, poid_rev
        FROM pin.item_t i
       WHERE     billinfo_obj_id0 = var1
             AND status = 1;

   TYPE fetch_array IS TABLE OF s_cur%ROWTYPE;

   TYPE fetch_array2 IS TABLE OF s_cur2%ROWTYPE;

   s_array    fetch_array;
   s_array2   fetch_array2;
BEGIN
   EXECUTE IMMEDIATE 'truncate table tmp_hotbill_flist';

   OPEN s_cur;

   LOOP
      FETCH s_cur BULK COLLECT INTO s_array LIMIT 100;

      FOR i IN 1 .. s_array.COUNT
      LOOP
         str := NULL;
         str := 'r << e 1';
         str :=
               str
            || CHR (10)
            || '0 PIN_FLD_POID           POID [0] 0.0.0.1 /account '
            || TO_CHAR (s_array (i).account_obj_id0);
         ctr := 0;

         BEGIN
            OPEN s_cur2 (s_array (i).poid_id0);

            LOOP
               FETCH s_cur2 BULK COLLECT INTO s_array2;

               FOR i IN 1 .. s_array2.COUNT
               LOOP
                  str :=
                        str
                     || CHR (10)
                     || '0 PIN_FLD_ITEMS         ARRAY ['
                     || TO_CHAR (ctr)
                     || '] allocated 20, used 1';
                  str :=
                        str
                     || CHR (10)
                     || '1     PIN_FLD_ITEM_OBJ       POID [0] 0.0.0.1 '
                     || TO_CHAR (s_array2 (i).poid_type)
                     || ' '
                     || TO_CHAR (s_array2 (i).poid_id0)
                     || ' '
                     || TO_CHAR (s_array2 (i).poid_rev)
                     || '';
                  ctr := ctr + 1;
               END LOOP;

               EXIT WHEN s_cur2%NOTFOUND;
            END LOOP;

            CLOSE s_cur2;
         EXCEPTION
            WHEN OTHERS
            THEN
               RAISE_APPLICATION_ERROR (-20000, s_array (i).bill_info_id);
         END;

         str :=
               str
            || CHR (10)
            || '0 PIN_FLD_PROGRAM_NAME    STR [0] "Testnap HOTBILL [Proj. LionHeart]"';
         str := str || CHR (10) || 'e';
         str := str || CHR (10) || 'xop PCM_OP_BILL_MAKE_BILL_NOW 0 1';

         INSERT INTO tmp_hotbill_flist
                 VALUES (
                           s_array (i).bill_info_id,
                           str,
                           'HOTBILL_' || s_array (i).bill_info_id || '.nap');
      END LOOP;

      EXIT WHEN s_cur%NOTFOUND;
   END LOOP;

   CLOSE s_cur;

   COMMIT;
END;
/

我已经尝试了数百条记录,但是一切正常,但是拥有一万多条记录使该过程运行了很长时间。

谢谢, 内尔茨基

0 个答案:

没有答案