Oracle :一次数据库连接,返回多个结果集
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle :一次数据库连接,返回多个结果集相关的知识,希望对你有一定的参考价值。
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 :一次数据库连接,返回多个结果集的主要内容,如果未能解决你的问题,请参考以下文章