使用批量收集将数据附加到表变量中

时间:2016-02-18 10:53:34

标签: database oracle rdbms

我正在尝试将数据附加到表变量中。但这种方法正在覆盖数据。而且,我得到的值是 i = 50 。有什么方法可以用来在for循环中追加数据。请帮助

TYPE employee_info_t IS TABLE OF enrolcols; 
 l_enro   employee_info_t:=employee_info_t();

FOR i IN 40..50
    LOOP
select   i+1,id + i ,
         0,
         'T',
         '08',
         0,
         00,
         '08',
         'PAS',
         'BULK',
         'BULKLOAD',
         system_timestamp,
         system_timestamp   bulk collect into l_enro from dual;
end loop;

2 个答案:

答案 0 :(得分:0)

您不需要在此处使用批量收集声明。从sql加载集合时使用批量收集。 如果我找不到你的代码,你想在plsql中填充集合。尝试类似的东西。

TYPE employee_info_t IS TABLE OF enrolcols; 
 l_enro   employee_info_t:=employee_info_t();
FOR i IN 40..50
    LOOP
    l_enro.extend(1);
    l_enro(l_enro.COUNT) := enrolcols(i+1,id + i ,
                             0,
                             'T',
                             '08',
                             0,
                             00,
                             '08',
                             'PAS',
                             'BULK',
                             'BULKLOAD',
                             system_timestamp,
                             system_timestamp);
end loop;

答案 1 :(得分:0)

您可以使用分层查询在没有循环的情况下执行此操作:

select enrolcols(
         LEVEL+40,
         id + 39 + LEVEL,
         0,
         'T',
         '08',
         0,
         00,
         '08',
         'PAS',
         'BULK',
         'BULKLOAD',
         system_timestamp,
         system_timestamp
       )
bulk collect into l_enro
from dual
CONNECT BY LEVEL <= 11;