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

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

2010-08-19 16:27 525 查看
1、建立包规范

create or replace package QX_GDJTJ is

-- Author : liuwei
-- Created : 2010-8-20 10:20:05
-- 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#调用,返回结果集

代码 1 public static DataSet GetDataSet(string gdjId, string proName, string[] cursors)
2 {
3 OracleConnection Conn = GetConn();
4 DataSet ds = new DataSet();
5 try
6 {
7 OracleCommand cmd = new OracleCommand();
8 cmd.Connection = Conn;
9 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐