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;
-- 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;
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 }
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 }