1、先要声明全局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 )(2)CREATE OR REPLACE TYPE "DDD_BY_DEPT_STATISTISC_TB" is table of DDD_BY_DEPT_STATISTISC--包含对象的table
2、建立一个带返回值的函数
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_TBiso_tb TP_ANTIBIOTIC_STATISTISC_TB := TP_ANTIBIOTIC_STATISTISC_TB();i number := 0;TIME_TYPES VARCHAR2(20):=TIME_TYPE;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;begin for Temp in cur loop--循环将游标里的对象赋值到装对象的集合中 o_tb.extend;-------A i := i + 1;----------B 每次向o_tb添加对象时都要进行AB操作 o_tb(i) := TP_ANTIBIOTIC_STATISTISC (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); end loop; return o_tb;end fn_get_antib_statistisc;