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;
}
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;
}
相关文章推荐
- Oracle :一次数据库连接,返回多个结果集
- PHP mysqul连接数据库,执行查询语句,打印返回结果集和断开数据库
- oracle:数据库查询返回结果集的默认值
- Advanced Installer 数据库连接字段参数和返回参数
- oracle 返回结果集的自定义函数 数据库管道
- ado.net连接模式访问数据库中datareader的返回多个结果集和mars的使用
- 方正快速开发平台中C#调用oracle返回参数,结果集
- 数据库操作_连接SQL Server数据库示例;连接ACCESS数据库;连接到 Oracle 数据库示例;SqlCommand 执行SQL命令示例;SqlDataReader 读取数据示例;使用DataAdapter填充数据到DataSet;使用DataTable存储数据库表;将数据库数据填充到 XML 文件;10 使用带输入参数的存储过程;11 使用带输入、输出参数的存储过程示;12 获得数据库中表的数目和名称;13 保存图片到SQL Server数据库示例;14 获得插入记录标识号;Exce
- JDBC oracle 数据库连接成功,但是ResultSet返回结果总是空
- 一次web 服务器无法连接上oracle 数据库的故障处理
- JAVA数据库处理(连接,数据查询,结果集返回)
- oracle profile Idle_time设置(修改Oracle 数据库连接参数)
- 调用带参数的存储过程,并返回结果集--oracle
- 【Oracle】记一次数据库连接没有关闭导致数据库宕机的排查过程
- JDBC连接数据库返回结果集的Key值
- 跨越Oracle和MSSQL关系数据库开发 -- 02 Oracle和MSSQL返回结果集区间的方法
- PL/SQL Developer连接本地Oracle 11g 64位数据库
- ORACLE自动断开数据库连接解决办法
- 事务管理最佳实践多余的话之一 ----“每次请求,一次数据库连接,一次事务”是不是金科玉律?
- TNS-12519与processes参数设置;jdbc 连接oracle 报 ORA-12519, TNS:no appropriate service handler found 问题解决