在下面的代码中我试图将nestedTable payment_obj从父进程传递给子进程,但是在子进程中我无法将数据插入到嵌套表中,因为它甚至在父进程初始化后抛出ERROR-对未初始化集合的引用“ *原因:嵌套表或varray的元素或成员函数 被引用(需要初始化集合) 没有收集已经初始化。
我将数据收集到嵌套表中,需要在子程序中插入支付表并将数据插入到父程序中嵌套表中收集的支付表中。如果无法使用嵌套表,如何实现此类要求。
buildTypes {
release {
debuggable false
minifyEnabled false
useProguard true
consumerProguardFiles 'proguard-rules.pro'
}
}
答案 0 :(得分:0)
程序prepare_payments
需要初始化payment_obj
。
我不确定这是什么意思,但以下运行没有错误:
create table payment1 (payment_id number);
create table payments (puid integer);
insert into payments (puid) values (1);
create or replace package pkg_payment
as
procedure process_payments;
end pkg_payment;
/
create or replace package body pkg_payment as
type typ_payment is record
( payment_id payment1.payment_id%type );
type tab_typ_payment is table of typ_payment;
procedure prepare_payments
( payment_obj out tab_typ_payment )
is
tab_typ_payment_index number(2) := 0;
begin
payment_obj := tab_typ_payment(); -- Initialised here
payment_obj.extend;
tab_typ_payment_index := payment_obj.count;
payment_obj(tab_typ_payment_index).payment_id := tab_typ_payment_index;
end prepare_payments;
procedure process_payments is
payment_obj tab_typ_payment := tab_typ_payment();
cursor c_puids_cur is
select puid from payments;
type puids is table of c_puids_cur%rowtype;
puids_obj puids := puids();
begin
open c_puids_cur;
loop
fetch c_puids_cur bulk collect into puids_obj limit 100;
for i_row_puid in 1 .. puids_obj.count loop
prepare_payments(payment_obj);
end loop;
exit when c_puids_cur%notfound;
end loop;
close c_puids_cur;
forall i in 1 .. payment_obj.count save exceptions
insert into payment1 values payment_obj (i);
end process_payments;
end pkg_payment;