无法将数据添加到Oracle自定义记录-错误-下标超出计数
我已经创建了定制的Oracle记录类型,我正在尝试用一些值填充,并尝试在另一个存储过程中访问相同的值。实际上,我将从Java调用—我在Java中也收到了相同的错误,但我收到了下标超出计数的错误消息 我只是一个存储过程的初学者。 下面是我所做的 Oracle客户记录类型 将值填充到记录类型的存储过程无法将数据添加到Oracle自定义记录-错误-下标超出计数,oracle,user-defined-types,Oracle,User Defined Types,我已经创建了定制的Oracle记录类型,我正在尝试用一些值填充,并尝试在另一个存储过程中访问相同的值。实际上,我将从Java调用—我在Java中也收到了相同的错误,但我收到了下标超出计数的错误消息 我只是一个存储过程的初学者。 下面是我所做的 Oracle客户记录类型 将值填充到记录类型的存储过程 create or replace PROCEDURE getLearnerMapDetails(learnerMapCustomRecord out learnerMapCustomRecordTa
create or replace PROCEDURE getLearnerMapDetails(learnerMapCustomRecord out learnerMapCustomRecordTable) as
cursor c1 is select object_name,status from user_objects where rownum <= 2;
c c1%rowtype;
i number:=1;
begin
learnerMapCustomRecord := learnerMapCustomRecordTable();
open c1;
loop
fetch c1 into c;
EXIT WHEN C1%NOTFOUND;
dbms_output.put_line(c.object_name||'==>'||c.status);
-- learnerMapCustomRecord.extend;
learnerMapCustomRecord(I).activityName:=C.OBJECT_NAME;
learnerMapCustomRecord(i).activityDescn:=c.status;
i:=i+1;
end loop;
end;
你能解释一下我做错了什么吗?几个问题:
尽管存在.extend方法,但您没有扩展集合。。。评论说。
您没有实例化对象类learnerMapCustomRecord。
您没有关闭光标c1。
您的输出参数与您的类具有相同的名称,由于默认的标识符范围解析,因此实际上使对象类的实例化更加困难。
您对SQL引擎进行了太多的往返,并且使用逐行获取(您可以对循环执行常规游标获取或批量获取)为自己做了太多的工作。
解决方案:
create or replace PROCEDURE getLearnerMapDetails(theOutput out learnerMapCustomRecordTable)
as
cursor c1 is select object_name,status from user_objects where rownum <= 2;
c c1%rowtype;
begin
theOutput := learnerMapCustomRecordTable();
open c1;
loop
fetch c1 into c;
EXIT WHEN C1%NOTFOUND;
dbms_output.put_line(c.object_name||'==>'||c.status);
theOutput.extend();
theOutput(theOutput.last) := new learnerMapCustomRecord(
activityName => c.object_name,
activityDescn => c.status
);
end loop;
close c1;
end;
。。。随着SQL engnie往返次数的减少
create or replace PROCEDURE getLearnerMapDetails(theOutput out learnerMapCustomRecordTable)
as
cursor c1 is select object_name,status from user_objects where rownum <= 2;
begin
theOutput := learnerMapCustomRecordTable();
for c in c1 loop
dbms_output.put_line(c.object_name||'==>'||c.status);
theOutput.extend();
theOutput(theOutput.last) := new learnerMapCustomRecord(
activityName => c.object_name,
activityDescn => c.status
);
end loop;
end;
。。。如果你想用硬汉的方式,那么你可以这样做
create or replace PROCEDURE getLearnerMapDetails(theOutput out learnerMapCustomRecordTable) as
begin
select new learnerMapCustomRecord(
activityName => object_name,
activityDescn => status
)
bulk collect into theOutput
from user_objects
where rownum <= 2;
end;
享受。您的光标是否返回?因为它是嵌套表可以容纳的最大值。
create or replace PROCEDURE getLearnerMapDetails(theOutput out learnerMapCustomRecordTable)
as
cursor c1 is select object_name,status from user_objects where rownum <= 2;
begin
theOutput := learnerMapCustomRecordTable();
for c in c1 loop
dbms_output.put_line(c.object_name||'==>'||c.status);
theOutput.extend();
theOutput(theOutput.last) := new learnerMapCustomRecord(
activityName => c.object_name,
activityDescn => c.status
);
end loop;
end;
create or replace PROCEDURE getLearnerMapDetails(theOutput out learnerMapCustomRecordTable) as
begin
select new learnerMapCustomRecord(
activityName => object_name,
activityDescn => status
)
bulk collect into theOutput
from user_objects
where rownum <= 2;
end;