Insert data from pl/sql table type to another pl/sql table type

2k views Asked by At

I am just wondering whether it is possible to insert data from one pl/sql table to another using bulkcollect?

I am trying it out but looks like it is not possible conceptually and the only way is to loop through the Pl/sql table .

Any insights would be really helpful. Thanks


below is the simplified version of what i am trying. i think i am making some conceptual mistake here . hence it is not working:

DECLARE 
TYPE ROWTBL IS TABLE OF BW_COLUMN.NAME%TYPE ;
PL_TBL_ROW ROWTBL;

TYPE COLNAME_TBL IS TABLE OF BW_COLUMN.NAME%TYPE ;
PL_TBL_COLNAME COLNAME_TBL;

BEGIN

   SELECT NAME 
   BULK COLLECT INTO PL_TBL_ROW 
   FROM TBL_COL WHERE TBL_ID = 2000081;


   SELECT NAME 
   BULK COLLECT INTO PL_TBL_COLNAME 
   FROM PL_TBL_ROW;

END;
1

There are 1 answers

0
Bob Jarvis - Слава Україні On

BULK COLLECT is a mechanism for efficiently reading data into PL/SQL data structures so they can be processed by PL/SQL code. You can certainly use this approach for copying data from one table to another but I suspect it will probably take more time than the simpler approach of using an INSERT statement such as

BEGIN
  INSERT INTO SOME_TABLE (COL_1, COL_2, COL_N)
    SELECT COL_1, COL_2, COL_N
      FROM SOME_OTHER_TABLE
      WHERE SOME_FIELD = SOME_OTHER_VALUE;
END;

Best of luck.