程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> 其他數據庫知識 >> 更多數據庫知識 >> 存儲過程返回數組對象示例代碼

存儲過程返回數組對象示例代碼

編輯:更多數據庫知識
其實就相當於返回List裡面放的對象數據,定義如下

1.創建存儲過程對象
復制代碼 代碼如下:
CREATE OR REPLACE TYPE "T_ACCOUNT_MONTH"
as object(
ACCOUNT_ID NUMBER,
INIT_AMOUNT NUMBER,
DEBIT_AMOUNT NUMBER,
CREDIT_AMOUNT NUMBER
)

2.創建存數過程數組
復制代碼 代碼如下:
CREATE OR REPLACE TYPE "T_ACCOUNT_MONTH_TABLE"
as table of t_account_month

3.創建存儲過程
復制代碼 代碼如下:
create or replace function account_month(tDate IN DATE)
return t_account_month_table pipelined
as
v_account_month t_account_month;
v_date DATE;
begin
v_date:=tDate;
IF v_date IS NULL THEN
v_date:=sysdate;
END IF;
for myrow in (
select d.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
from ACCOUNT_DAILY_VEIW d
group by 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);
end loop;
return;
end;
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved