开发者

Bulk collecting with LIMIT clause into nested table in PL/SQL

开发者 https://www.devze.com 2023-04-02 19:19 出处:网络
As the title says, how to bulk collect into a nested table with LIMIT clause? In the following examples, cur_data is a nested table which gets overwritten on the subsequent BULK COLLECT. I have seen E

As the title says, how to bulk collect into a nested table with LIMIT clause? In the following examples, cur_data is a nested table which gets overwritten on the subsequent BULK COLLECT. I have seen EXTEND used for adding data to a nested table. Is there any way to do something similar with BULIK COLLECT?

 开发者_运维百科 OPEN cur;
  LOOP
      FETCH cur bulk collect INTO cur_data LIMIT 500;
      EXIT WHEN cur_data%COUNT=0;
  END LOOP;
  CLOSE cur;
  /*Data gets overwritten with empty cursor--> No data in cur_data here*/


  OPEN cur;
  FETCH cur bulk collect INTO cur_data;
  CLOSE cur;
  /*No Problems--> All data fetched into cur_data */

Thanks in advance.


I'm not sure that I understand the problem you are trying to solve.

If you want to load every row the is fetched from the cursor into your collection, there is no point to using the LIMIT clause. Simply

OPEN cur;
FETCH cur
 BULK COLLECT INTO cur_data;
<<do something with the data>>
CLOSE cur;

If you want to use the LIMIT clause, that implies that you want to process a subset of the data returned from the cursor at a time in order to limit the amount of the server's PGA that is allocated to your collection. Assuming you are doing that

OPEN cur;
LOOP
  FETCH cur
   BULK COLLECT INTO cur_data LIMIT 500;
  EXIT WHEN cur_data%count = 0;
  <<do something with the 500 elements in cur_data>>
END LOOP;
CLOSE cur;

It doesn't make any sense to fetch the data 500 rows at a time inside your loop and then do something with the collection outside of the loop.

0

精彩评论

暂无评论...
验证码 换一张
取 消