Where The Streets Have No Name

BULK COLLECT & FORALL vs. CURSOR & FOR-LOOP 본문

Developement/DataBase

BULK COLLECT & FORALL vs. CURSOR & FOR-LOOP

highheat 2008. 1. 31. 22:22

참조 : https://geraldonit.com/2007/09/27/bulk-collect-forall-vs-cursor-for-loop/

CREATE OR REPLACE PROCEDURE BULK_COLLECT_QUERY
IS
   TYPE SOWNER IS TABLE OF VARCHAR2 (30);
   TYPE SNAME IS TABLE OF VARCHAR2 (30);
   TYPE STYPE IS TABLE OF VARCHAR2 (19);

   L_SOWNER SOWNER;
   L_SNAME SNAME;
   L_STYPE STYPE;
BEGIN
   DBMS_OUTPUT.PUT_LINE ('Before Bulk Collect: ' || SYSTIMESTAMP);

   SELECT OWNER,
          OBJECT_NAME,
          OBJECT_TYPE
   BULK COLLECT INTO L_SOWNER,
           L_SNAME,
           L_STYPE
     FROM ALL_OBJECTS;

   DBMS_OUTPUT.PUT_LINE ('After Bulk Collect: ' || SYSTIMESTAMP);
   FORALL INDX IN L_SNAME.FIRST .. L_SNAME.LAST
      INSERT INTO TEMP
           VALUES (L_SOWNER (INDX), L_SNAME (INDX), L_STYPE (INDX));
   DBMS_OUTPUT.PUT_LINE ('After FORALL: ' || SYSTIMESTAMP);
   COMMIT;
END;
/