一个通过Oracle8i存储过程返回记录集的程序包(存储过程)
2008-05-13 16:07:15 来源:WEB开发网提示:在Oracle8i中,如果需要通过存储过程返回结果集, 需要使用游标!
CREATE OR REPLACE PACKAGE BODY "SMS_PAY"."SMSMAINT"
IS
--功能描述:查询代理银行交易流水信息 writer: wang haibo 2004-08-24
PROCEDURE GetAgtBankFlow(AreaCode in varchar2,KeyWord in varchar2,startTradeDate in varchar2,endTradeDate in varchar2,Re_CURSOR OUT T_CURSOR,ret out number)
is
IsExists number;
strSQL VARCHAR2(2048);
Begin
--检查临时表是否已经存在,如果不存在,则创建,否则插入数据 start
Select Count(*) Into IsExists from all_tables Where Table_Name='TEMPAGTBANKFLOW';
IF IsExists=0 Then
strSQL:='CREATE GLOBAL TEMPORARY TABLE SMS_PAY.TEMPAgtBankFlow
(AGTID VARCHAR2(13) ,BANK_GLIDE Number(12),TradeType VARCHAR2(20),Trade_Money Number(14,2),
TRADEDATE VARCHAR2(10),TRADETIME VARCHAR2(8),BankNAME VARCHAR2(30),
AreaCode Varchar2(30), AreaName VARCHAR2(30),State VARCHAR2(30),CheckFlag Number(1),
StatusFlag Number(1),SuccFlag Number(1)) on commit preserve rows';
--把临时表的创建选项由on commit delete rows改为on commit preserve rows;
--否则在调用的时候,回出现ORA-08103: object no longer exists
Execute Immediate strSQL;
Else
Execute immediate 'Truncate table Sms_pay.TEMPAGTBANKFLOW';
End IF;
--检查临时表是否已经存在,如果不存在,则创建,否则插入数据 end
---功能:把满足条件的一级代理商转帐信息导入数据库 Start
/*strSQL:='Insert Into TEMPAgtBankFlow
Select A.Agent_Mobile,A.Bank_Glide,
Decode(A.OPTCode,''100'',''交款交易'',''101'',''交款冲正'',''900'',''抹帐交易'',''类型不明'') as TradeType,A.Trade_Money,
TO_Char(To_Date(A.Trade_Date,''YYYYMMDD''),''YYYY-MM-DD'') as TradeDate,
TO_Char(To_Date(A.Trade_Time,''hh24miss''),''hh24:mi:ss'') as TradeTime,B.BankName,C.AreaCode,C.AreaName,
(Case When CheckFlag=-1 Then ''/Images/state_rollback.gif'' When SuccFlag=-1 Then ''/Images/state_cancel.gif'' When StatusFlag=-1 Then ''/Images/state_unnormal.gif'' Else ''/Images/state_normal.gif'' End) as State
From Bank_Stream_Account A,BankInfoConfig B,AreaConfig C,FstAgtAccount D
Where A.Bank_ID=B.BankCode And Trim(A.Agent_Mobile)=D.AgtID And C.CityCode=D.CityCode ';
IF AreaCode!='0' Then --条件1: 选择所有地区的信息
strSQL:=strSQL || ' And Trim(C.AreaCode)=''' || AreaCode || ''' ';
End IF;
IF TradeDate!=' ' Then --条件2: 选择所有地区的信息,选择所有交易日期的信息
strSQL:=strSQL || ' And TO_Char(To_Date(A.Trade_Date,''YYYYMMDD''),''YYYY-MM-DD'')=''' || TradeDate || ''' ';
End If;
IF KeyWord!=' ' Then --条件3: 选择所有地区的信息,选择所有交易日期的信息,选择和查询关键字匹配的信息
strSQL:=strSQL || ' And (D.AgtID Like''%' || KeyWord || '%'' Or TO_Char(A.BANK_GLIDE) Like ''%' || KeyWord || '%'' Or B.BankName Like ''%' || KeyWord ||'%'') ';
End If;
Execute Immediate strSQL;
---功能:把满足条件的一级代理商转帐信息导入数据库 End
更多精彩
赞助商链接