我有两种类型:
create or replace
type CASES_TYPE_N IS object(
CASEID VARCHAR2(128),
FirstNumber VARCHAR2(32),
DLR number
);
create or replace
TYPE CASES_TABLE_N AS TABLE OF CASES_TYPE_N;
并与它一起打包:
create or replace
PACKAGE BANKRUPT_TEST AS
procedure BANKRUPT_TEST_p(
pType in integer,
pRequestDate in varchar2,
CasesList_1 out CASES_TABLE_N,
ResultCode out integer,
ErrorText out varchar2);
END BANKRUPT_TEST;
create or replace
PACKAGE BODY BANKRUPT_TEST AS
procedure BANKRUPT_TEST_p(
pType in integer,
pRequestDate in varchar2,
CasesList_1 out CASES_TABLE_N,
ResultCode out integer,
ErrorText out varchar2) AS
BEGIN
ResultCode := pType;
ErrorText := pRequestDate;
select CASES_TYPE_N(CaseID,
FirstNumber,
dlr
) bulk collect
into CasesList_1
from ( select
'CaseID' as CaseID,
'Fnum' as FirstNumber,
15 as dlr
from dual
)
;
NULL;
END BANKRUPT_TEST_p;
END BANKRUPT_TEST;
所有这些都是用Oracle SQL Developer编写并运行的 因此,我只收到变量ResultCode和ErrorText。而且我也应该从CasesList_1获取数据。但我不是。 我没有收到任何编译错误。 它必须使用类型,而不是游标。 你能帮忙吗?
答案 0 :(得分:0)
您可以使用小型PLSQL块调用您的过程;例如,以下运行您的过程并打印结果:
declare
p1_in integer := 10;
p2_in varchar2(10) := 'xxx';
p1_out CASES_TABLE_N;
p2_out integer;
p3_out varchar2(10);
begin
BANKRUPT_TEST.BANKRUPT_TEST_p(
pType => p1_in ,
pRequestDate => p2_in ,
CasesList_1 => p1_out ,
ResultCode => p2_out ,
ErrorText => p3_out
);
if p1_out.count > 0 then
for i in p1_out.first .. p1_out.last loop
dbms_output.put_line(i || ' - ' ||
p1_out(i).caseId || ' - ' ||
p1_out(i).firstNumber || ' - ' ||
p1_out(i).dlr
);
end loop;
end if;
dbms_output.put_line(p2_out);
dbms_output.put_line(p3_out);
end;
结果:
1 - CaseID - Fnum - 15
10
xxx
如果你在SQLPLUS中运行它,你应该先让SET SERVEROUTPUT ON
启用打印。
如果在其他客户端中运行此命令,则必须检查是否在您的环境中启用了SERVEROUTPUT;方式因客户而异。
答案 1 :(得分:0)
结果这是工作代码。
create or replace
procedure BANKRUPT_TEST_p1(
pType in integer,
in varchar2,
CasesList_1 out CASES_TABLE_N,
ResultCode out integer,
ErrorText out varchar2) IS
nCur number;
BEGIN
ResultCode := pType;
ErrorText := pRequestDate;
begin
CasesList_1:=CASES_TABLE_N();
exception when others then null;
end;
for rec in(
select distinct CaseID,
FirstNumber,
DLR
from AA_TABLE
where DownloadDate = pRequestDate and ClientID is not null
) loop
CasesList_1.extend;
nCur := CasesList_1.last;
CasesList_1(nCur) := CASES_TYPE_N(null, null, null);
begin
CasesList_1(nCur).CASEID := rec.caseid;
exception when others then null;
end;
begin
CasesList_1(nCur).FirstNumber := rec.firstnumber;
exception when others then null;
end;
begin
CasesList_1(nCur).DLR := rec.dlr;
exception when others then null;
end;
end loop;
NULL;
END BANKRUPT_TEST_p1;
END BANKRUPT_TEST1;