Oracle: a database connection. Multiple result sets (with parameters) are returned )!

Source: Internet
Author: User

1. Establish package specifications

Create or replace package QX_GDJTJ is

-- Author: liuwei
-- Created: 10:20:05
-- Purpose: Count master device defects

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 a package

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
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' % qualified % 'and cljg not like' % unqualified % ') from dual;
OPEN cur_GDJQXTJ2
Select (select count (0) from HVM_VIEW_QX where voltage = '220k' and gdjid = cur_id)-(select count (0) from HVM_VIEW_QX where voltage = '220k' and gdjid = cur_id and cljg like '% qualified %' and cljg not like '% unqualified %') from dual;
OPEN cur_GDJQXTJ3
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' % qualified % 'and cljg not like' % unqualified % ') from dual;
End GETGDJQXTJ;
End QX_GDJTJ;

3. C # Call, return result set

 

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.