• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
gooliugle
博客园    首页    新随笔    联系   管理    订阅  订阅
Oracle :一次数据库连接,返回多个结果集(带参数)!

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;
10                 cmd.CommandType = CommandType.StoredProcedure;
11                 cmd.Parameters.Add("cur_id", OracleType.VarChar).Value = gdjId;
12                 for (int i = 0; i < cursors.Length; i++)
13                 {
14                     cmd.Parameters.Add(cursors[i], OracleType.Cursor).Direction = ParameterDirection.Output;
15                 }
16                 OracleDataAdapter da = new OracleDataAdapter(cmd);
17                 da.Fill(ds);
18             }
19             catch (System.Data.OracleClient.OracleException ex)
20             {
21                 throw new Exception(ex.Message);
22             }
23             finally
24             {
25                 Conn.Close();
26             }
27             return ds;
28         }



 

posted on 2010-08-19 16:27  gooliugle  阅读(2347)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3