码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2016-10-14 09:54:40      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:

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 is
PROCEDURE GETGDJQXTJ
(
    cur_id in varchar,
    cur_GDJQXTJ1 OUT T_CURSOR,
    cur_GDJQXTJ2 OUT T_CURSOR,
    cur_GDJQXTJ3 OUT T_CURSOR
)
IS
BEGIN
OPEN cur_GDJQXTJ1 FOR
select (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 FOR
select (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 FOR
select (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 = 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 :一次数据库连接,返回多个结果集

标签:

原文地址:http://www.cnblogs.com/arxive/p/5959031.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!