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

VB调用ORACLE存储过程返回多记录集

2007-05-21 12:54 423 查看
一直没有写原创的习惯,每次都是从别的贴子拷贝过来。实在是不好意思。最近想把自己做的一个项目中所解决的问题和大家共享一下。希望对遇见这种情况的朋友有所帮助。
程序中要用到VB调用ORACLE的存储过程,存储过程返回的是多记录集。要是在C#中这种情况很好解决。但是到了VB中。情况就不一样了。在CSDN上也查了。都没有人说出完整的解决的解决方案。经过几天的摸索。终于搞定。下面是存储过程和相应的VB调用代码。
存储过程如下:大家只需关心返回的记录集

CREATE OR REPLACE PACKAGE BODY REPORT AS
2 PROCEDURE p_Report_Yysc_Zyq(strDate in date,v_result1 out t_cursor,v_result2 out t_cursor)
3 is
4 nCount int;
5 d_date date;
6 begin
7
8 open v_result1 for SELECT SSDW,sum(nvl(ZJS,0)) ZJS,sum(nvl(KJS,0)) KJS,sum(nvl(RCY,0)) RCY,sum(nvl(RC_Y,0)) RC_Y,sum(nvl(YLBH,0)) YLBH,sum(nvl(Y_LBH,0)) Y_LBH,sum(nvl(YCYL,0)) YCYL,sum(nvl(NCYL,0)) NCYL,round((1- (sum(nvl(RC_Y,0))/0.823/sum(nvl(RCY,0)))),3)*100 HS FROM REPORT_YYSC_ZYQ where TRUNC(rq)=TRUNC(d_date) and HZLX='1' group by SSDW;
9 open v_result2 for select * from REPORT_YYSC_ZYQ where trunc(RQ)=trunc(strDate) and HZLX='1';
10 end p_Report_Yysc_Zyq;
VB调用的代码如下:用下面的两种方式都可以调用:

Public Function ExecProcByODBC()Function ExecProcByODBC(ByVal ProcName As String, ByVal sDate As Date) As Variant
3Public Function ExecProc()Function ExecProc(ByVal ProcName As String, ByVal sDate As Date) As Variant
3Dim mycmd As ADODB.Command
4Set mycmd = New ADODB.Command
5Dim rs As New ADODB.Recordset
6Dim rs1 As New ADODB.Recordset
7Set mycmd.ActiveConnection = MyCnt
8mycmd.CommandType = adCmdStoredProc
9mycmd.CommandText = ProcName
10mycmd.Parameters.Append mycmd.CreateParameter("sDate", adDate, adParamInput, 16, sDate)
13Set rs = mycmd.Execute
25Set ExecProc = rs
26Set rs = Nothing
27Set mycmd = Nothing
28End Function
最后还要强调一点的时候,在写连接字符串的时候。务必如下。否则在用VB的NEXTRECORDSET会调用不成功。
strCnt = "Provider=OraOLEDB.Oracle.1;Password=1;Persist Security Info=True;User ID=1;Data Source=ORA92;PLSQLRSet=1"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: