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;
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;
相关文章推荐
- 重新整理后的Oracle OAF学习笔记——4.应用构建基础之实现视图
- Oracle 10g总结之基础应用
- Oracle442个应用场景------------基础应用场景
- oracle Streams基础之应用进程 (6)
- ORACLE基础学习-RMAN应用--归档模式有备份,丢失数据文件恢复
- Oracle 10g总结之基础应用
- oracle基础知识2----pl/sql基础(基本语法、光标、例外、应用)
- oracle Streams基础之应用进程 (7)
- ORACLE EBS 系统应用基础概述(A)
- oracle Streams基础之应用进程 (8)
- Oracle应用集成架构基础包
- ORACLE基础学习-RMAN应用之(归档模式无备份,丢失数据文件的恢复)
- Oracle442个应用场景------------基础应用场景
- Oracle 11g R1/R2 真正应用集群(RAC)基础
- oracle 应用开发总结(基础篇上)
- ORACLE EBS 系统应用基础概述(B)
- Oracle SQL语言应用基础
- oracle 应用开发总结(基础篇下)
- Oracle EBS 信用(Credit)额度(2)-基础应用
- ORACLE基础学习-RMAN应用-控制文件恢复