您的位置:首页 > 数据库 > Oracle

Oracle 基础应用。

2007-08-16 10:00 190 查看
函数返回游标类型的方法.以下是我写的一个返回游标类型的函数,但是我返回的游标总是空的,里面是有记录的。我下在想办法解决。贴下源代码:

CREATE OR REPLACE Function MXL_QUERY_TBCHANGE_SUM return sys_refcursor As out_curemp sys_refcursor;

Begin

Open out_curemp For Select t.*,t1.* ,(t.recivemoney-t1.cancelmoney) As realmoney From
(Select cunit_id, Count(*) As recivecount , sum(a.ncharge_fee)/100 As recivemoney
From tbcharge_fee a Where a.bsuccess=1
Group By a.cunit_id) t,
(Select cunit_id,Count(*) As cancelcount ,Sum(b.ncharge_fee)/100 As cancelmoney
From tbcharge_fee b Where b.nbcancel_fee=1
Group By b.cunit_id) t1
Where t.cunit_id=t1.cunit_id(+);
Return out_curemp;
End;

CREATE OR REPLACE Procedure MXL_CBM_CHANGE_SUM(begindate varchar2,enddate Varchar2,userid varchar2)
As
bdate Date;
edate Date;
Begin
bdate:=to_date(begindate,'yyyy-MM-dd');
edate:=to_date(enddate || ' 23:59:59','yyyy-MM-dd HH24:MI:SS');
----插入短信营业厅代理商收费汇总表 cperiod:帐期的格式:YYYYMM
Insert Into cbm_charge_sum(nserial, cunit_code, cuser_id, cperiod, cchannel_type, ncharge_fee_count, ncharge_fee_sum, ncancel_fee_count, ncancel_fee_sum, n_real_fee, dtsum_date, szsum_userid, cnote)
Select seq_cbm_changesum.nextval,t.cunit_id,'tbunit',substr(to_char(to_date(begindate,'yyyy-MM-dd'),'yyyymmdd'),0,6),
'tbunit',t.recivecount,t.recivemoney,t1.cancelcount,t1.cancelmoney,
(t.recivemoney-t1.cancelmoney) As realmoney,Sysdate,userid,'短信营业厅代理商收费汇总' From
(Select cunit_id, Count(*) As recivecount , sum(a.ncharge_fee)/100 As recivemoney
From tbcharge_fee@smsdblink a Where a.bsuccess=1 And a.dtcomplete>=bdate And a.dtcomplete<=edate
Group By a.cunit_id) t,
(Select cunit_id,Count(*) As cancelcount ,Sum(b.ncharge_fee)/100 As cancelmoney
From tbcharge_fee@smsdblink b Where b.nbcancel_fee=1 And b.dtcancel>=bdate And b.dtcancel<=edate
Group By b.cunit_id) t1
Where t.cunit_id=t1.cunit_id(+);
End;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: