我是第一次创建 PL/SQL 包。它看起来很简单,但我无法包装我的函数,该函数返回一个包中的表。
以下是我的包装规格:
CREATE OR REPLACE PACKAGE P_trdelclvr01 AS
FUNCTION fn_trdelclvr_QADJ return table_trdelclvr_QADJ;
END P_trdelclvr01;
/
以下是包体:
CREATE OR REPLACE PACKAGE BODY P_trdelclvr01 AS
type type_trdelclvr_QADJ as object(
TOTAL_CLAIMS INTEGER,
calculated_year INTEGER,
MTH varchar2(500),
CLAIM INTEGER,
CIW INTEGER,
PAPER INTEGER,
MBRECLAIM INTEGER,
PRVRDIALUP INTEGER,
PRVRIP INTEGER,
ELECTRONIC INTEGER
);
type table_trdelclvr_QADJ is table of type_trdelclvr_QADJ;
function fn_trdelclvr_QADJ
(P_CLAIM varchar2,
P_CIW varchar2,
P_PP varchar2,
P_PAPER varchar2,
P_MBR varchar2,
P_EDI varchar2,
P_MBR_NatApp varchar2,
P_CDAnet_DialUp varchar2,
P_CDAnet_IP varchar2,
P_CDAnet_ICA varchar2,
P_START_DATE date,
P_END_DATE date,
P_DENTAL varchar2,
P_IVR varchar2
);
--select * from table(fn_trdelclvr_QADJ(1,2,3,1,2,2,6,3,4,7,to_date('01/01/1990','mm/dd/yyyy'),to_date('12/12/2024','mm/dd/yyyy'),80,3));
return table_trdelclvr_QADJ
as
CURSOR CURSEUR_ETAPE
IS
select type_trdelclvr_QADJ(tbl.total_claims, tbl.calculated_year, tbl.mth, tbl.claim, tbl.ciw, tbl.paper, tbl.MbrEclaim, tbl.PrvrDialUp, tbl.PrvrIP, tbl.Electronic)
from
(
select
count(1) total_claims,
to_char(system_date,'YYYY') calculated_year,
to_char(system_date,'YYYY-MM') mth,
sum(decode(document_category, P_CLAIM ,1,0)) claim,
sum(decode(document_category, P_CIW ,1, P_PP ,1,0)) ciw,
sum(decode(document_source,P_PAPER,1,0)) paper,
sum(decode(document_source, P_MBR,decode(edi_app_source,P_MBR,1,0),0)
+ decode(document_source, P_EDI, decode(edi_app_source, P_MBR_NatApp, 1,0),0)) MbrEclaim,
sum(decode(document_source, P_EDI, decode(edi_app_source, P_CDAnet_DialUp, 1,0),0)) PrvrDialUp,
sum(decode(document_source, P_EDI,decode(edi_app_source, P_CDAnet_IP, 1,0),0)
+ decode(document_source, P_EDI, decode(edi_app_source, P_CDAnet_ICA, 1,0),0)) PrvrIP,
sum(decode(document_source, P_EDI, 1,0)) Electronic
from blu_adj_statistics adj
where system_date >= P_START_DATE
and system_date < P_END_DATE + 1
and claim_type = P_DENTAL
and claim_iteration = 1
and document_source <> P_IVR
and ( hsa_indicator is null )
group by to_char ( system_date , 'YYYY' ) ,
to_char ( system_date , 'YYYY-MM' )
ORDER BY 2 DESC,3 DESC
) tbl;
test_type table_trdelclvr_QADJ:=table_trdelclvr_QADJ();
BEGIN
OPEN CURSEUR_ETAPE;
LOOP
FETCH CURSEUR_ETAPE
BULK COLLECT INTO test_type;
EXIT WHEN CURSEUR_ETAPE%NOTFOUND;
END LOOP;
CLOSE CURSEUR_ETAPE;
RETURN test_type;
END;
END P_trdelclvr01;
/
提前致谢。
首先创建您的类型对象...
Create Or Replace Type type_trdelclvr_QADJ IS
object( TOTAL_CLAIMS INTEGER,
CALCULATED_YEAR INTEGER,
MTH varchar2(500),
CLAIM INTEGER,
CIW INTEGER,
PAPER INTEGER,
MBRECLAIM INTEGER,
PRVRDIALUP INTEGER,
PRVRIP INTEGER,
ELECTRONIC INTEGER
);
Create Or Replace Package P_trdelclvr01 AS
--
FUNCTION fn_trdelclvr_QADJ(p_Param1 VarChar2 := 'A') Return type_trdelclvr_QADJ;
--
END P_trdelclvr01;
create or replace Package Body
P_trdelclvr01 AS
Function fn_trdelclvr_QADJ(p_Param1 VarChar2 := 'A') Return type_trdelclvr_QADJ As
BEGIN
Declare
Cursor CURSEUR_ETAPE Is
Select type_trdelclvr_QADJ(tbl.total_claims, tbl.calculated_year, tbl.mth, tbl.claim, tbl.ciw, tbl.paper, tbl.MbrEclaim, tbl.PrvrDialUp, tbl.PrvrIP, tbl.Electronic)
From ( Select
100 total_claims,
'2024' calculated_year,
'2024-08' mth,
15 claim,
10 ciw,
5 paper,
0 MbrEclaim,
7 PrvrDialUp,
8 PrvrIP,
15 Electronic
From Dual
) tbl;
type_tbl type_trdelclvr_QADJ;
Begin
Open CURSEUR_ETAPE;
Fetch CURSEUR_ETAPE INTO type_tbl;
Close CURSEUR_ETAPE;
RETURN type_tbl;
End;
END fn_trdelclvr_QADJ;
END P_trdelclvr01;
SET SERVEROUTPUT ON
DECLARE
v_type_tbl type_trdelclvr_QADJ ;
BEGIN
v_type_tbl := P_trdelclvr01.fn_trdelclvr_QADJ('B');
dbms_output.put_line('Year_Month is ' || v_type_tbl.MTH);
END;
/
/* R e s u l t :
Year_Month is 2024-08
PL/SQL procedure successfully completed */