存储过程返回数组对象例子

来源:互联网 发布:订单生产进度跟踪软件 编辑:程序博客网 时间:2024/06/02 02:35
存储过程返回数组对象例子
 
其实就相当于返回List里面放的对象数据,定义如下
 
1.创建存储过程对象
?
1
2
3
4
5
6
7
CREATEOR REPLACE TYPE "T_ACCOUNT_MONTH"
asobject(
  ACCOUNT_ID NUMBER,
  INIT_AMOUNT NUMBER,
  DEBIT_AMOUNT NUMBER,
  CREDIT_AMOUNT NUMBER
)

 

2.创建存数过程数组
?
1
2
CREATEOR REPLACE TYPE "T_ACCOUNT_MONTH_TABLE"                                        
astable of t_account_month

 

3.创建存储过程
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
createor replace function account_month(tDate INDATE)
returnt_account_month_table pipelined
as
v_account_month t_account_month;
v_dateDATE;
begin
  v_date:=tDate;
  IF v_date ISNULL THEN
    v_date:=sysdate;
  ENDIF;
formyrow in(
        selectd.ACCOUNT_ID,
               sum(decode(sign(d.create_time-trunc(v_date,'month')),-1,
                     d.debit_unvoucher + d.debit_unposted +d.debit_posted - d.CREDIT_UNVOUCHER -d.CREDIT_UNPOSTED- d.CREDIT_POSTED_D,
                     0)) INIT_AMOUNT,
               sum(decode(sign(trunc(d.create_time,'year')-trunc(sysdate,'year')),0,
                     d.debit_unposted+d.debit_posted,
                     0)) DEBIT_AMOUNT,
               sum(decode(sign(trunc(d.create_time,'year')-trunc(sysdate,'year')),0,
                     d.credit_unposted+d.credit_posted,
                     0)) CREDIT_AMOUNT
         fromACCOUNT_DAILY_VEIW d
         groupby d.ACCOUNT_ID
  ) loop
v_account_month := t_account_month(
         myrow.ACCOUNT_ID,
         myrow.INIT_AMOUNT,
         myrow.DEBIT_AMOUNT,
         myrow.CREDIT_AMOUNT
);
pipe row (v_account_month);
endloop;
return;
end;
0 0