一、先要聲明全局type;而且,字段變量類型要爲object,不能爲record:函數
(1)CREATE OR REPLACE TYPE "DDD_BY_DEPT_STATISTISC" is object ( --創建一個對象
DEPT_CODE VARCHAR2(200),
DEPT_NAME VARCHAR2(200),
SYQD NUMBER,
ZKZTS NUMBER
)oop
(2)CREATE OR REPLACE TYPE "DDD_BY_DEPT_STATISTISC_TB" is table of DDD_BY_DEPT_STATISTISC--包含對象的tablecode
二、創建一個帶返回值的函數對象
create or replace function fn_get_antib_statistisc(BILLING_DATE_MIN IN varchar2, BILLING_DATE_MAX IN varchar2,TIME_TYPE IN VARCHAR2)--TIME_TYPE 發生=1結算=2
return TP_ANTIBIOTIC_STATISTISC_TB
is
o_tb TP_ANTIBIOTIC_STATISTISC_TB := TP_ANTIBIOTIC_STATISTISC_TB();
i number := 0;
TIME_TYPES VARCHAR2(20):=TIME_TYPE;get
cursor cur is--創建遊標,先把要返回的內容放在遊標裏
select patient_id,
pat_name,
doctor,
drdered_by,
dept_name,
visit_id,
sum(costs) costs,
rcpt_no,
statistisc_bz from antibiotic_statistisc
OPERATION_STATISTICS where date_time>=to_date(BILLING_DATE_MIN,'yyyy-mm-dd')
and date_time<to_date(BILLING_DATE_MAX,'yyyy-mm-dd')+1 and STATISTISC_BZ=TIME_TYPES group by patient_id,
pat_name,
doctor,
drdered_by,
dept_name,
visit_id,
rcpt_no,
statistisc_bz;
beginit
for Temp in cur loop--循環將遊標裏的對象賦值到裝對象的集合中
o_tb.extend;-------A
i := i + 1;----------B 每次向o_tb添加對象時都要進行AB操做
o_tb(i) := TP_ANTIBIOTIC_STATISTISC (io
Temp.patient_id,
Temp.pat_name,
Temp.doctor,
Temp.drdered_by,
Temp.dept_name,
Temp.visit_id,
Temp.costs,
Temp.rcpt_no,
'',
Temp.statistisc_bz
);table
end loop;
return o_tb;
end fn_get_antib_statistisc;function