首页 > 代码库 > Oracle :一次数据库连接,返回多个结果集

Oracle :一次数据库连接,返回多个结果集

gooliugle 原文 Oracle :一次数据库连接,返回多个结果集(带参数)!

 

1、建立包规范

create or replace package QX_GDJTJ is  -- Author  : xxx  -- Created : 2012-1-1  -- Purpose : 统计主设备缺陷  TYPE T_CURSOR IS REF CURSOR; PROCEDURE GETGDJQXTJ(    cur_id in varchar,    cur_GDJQXTJ1 OUT T_CURSOR,    cur_GDJQXTJ2 OUT T_CURSOR,    cur_GDJQXTJ3 OUT T_CURSOR);end QX_GDJTJ;

 

2、建立包体

create or replace package body QX_GDJTJ isPROCEDURE GETGDJQXTJ(    cur_id in varchar,    cur_GDJQXTJ1 OUT T_CURSOR,    cur_GDJQXTJ2 OUT T_CURSOR,    cur_GDJQXTJ3 OUT T_CURSOR)ISBEGINOPEN cur_GDJQXTJ1 FORselect (select count(0) from HVM_VIEW_QX where voltage=500kV and gdjid=cur_id )-(select count(0) from HVM_VIEW_QX where voltage=500kV and gdjid=cur_id and cljg like %合格% and cljg not like %不合格%) from dual;OPEN cur_GDJQXTJ2 FORselect (select count(0) from HVM_VIEW_QX where voltage=220kV and gdjid=cur_id )-(select count(0) from HVM_VIEW_QX where voltage=220kV and gdjid=cur_id and cljg like %合格% and cljg not like %不合格%) from dual;OPEN cur_GDJQXTJ3 FORselect (select count(0) from HVM_VIEW_QX where voltage=110kV and gdjid=cur_id )-(select count(0) from HVM_VIEW_QX where voltage=110kV and gdjid=cur_id and cljg like %合格% and cljg not like %不合格%) from dual;end GETGDJQXTJ;end QX_GDJTJ;

 

3、C#调用,返回结果集

public static DataSet GetDataSet(string gdjId, string proName, string[] cursors){    OracleConnection Conn = GetConn();    DataSet ds = new DataSet();    try    {    OracleCommand cmd = new OracleCommand();    cmd.Connection = Conn;    cmd.CommandText = proName;    cmd.CommandType = CommandType.StoredProcedure;    cmd.Parameters.Add("cur_id", OracleType.VarChar).Value =http://www.mamicode.com/ gdjId;    for (int i = 0; i < cursors.Length; i++)    {      cmd.Parameters.Add(cursors[i], OracleType.Cursor).Direction = ParameterDirection.Output;    }        OracleDataAdapter da = new OracleDataAdapter(cmd);        da.Fill(ds);    }    catch (System.Data.OracleClient.OracleException ex)    {        throw new Exception(ex.Message);    }    finally    {        Conn.Close();    }    return ds;}

 



 

Oracle :一次数据库连接,返回多个结果集