C # calls a stored procedure method with parameters--oracle "reprint"

Source: Internet
Author: User

1 because the eight reports of the crosstab are written in SQL , each report corresponds to a SQL statement that has more than one row, and cannot define the view because a parameter must be passed So we took advantage of the stored procedure implementation.

First, define the package and then define the package body to generate the dataset with . NET Calls

. NET calls the oracle stored procedure with parameters, returns the dataset

Oracle is a bit more complex, with the following steps:

Write the package definition file first in PL/SQL

CREATE OR REPLACE Package ZHBB as
TYPE t_cursor is REF cursor;
Procedure ZH11 (RQ in Char, io_cursor in Out t_cursor);

Procedure ZH12 (RQ in Char, io_cursor in Out t_cursor);

END ZHBB;

Second, write the definition file of the package body

CREATE OR REPLACE Package BODY ZHBB as

Procedure ZH11 (RQ in Char, io_cursor in off t_cursor) is

V_cursor T_cursor;

BEGIN

OPEN V_cursor for

Select * from AA where NY=RQ;

Io_cursor: = V_cursor;

END ZH11;

Procedure ZH12 (RQ in Char, io_cursor in off t_cursor) is

。。。。。

END ZH12;

. NET call methods:

public static DataTable getdatatable (string packagename,string proname,string connstring,string RQ)

{

connstring=" provider= msdaora.1; User Id=xx;data source=xx; Password=xx; "

Define the new link method, because the original driver "OraOLEDB.Oracle" does not meet the requirements, set to "Msdaora.1"

OleDbConnection raclecon = new OleDbConnection (connstring);

Oraclecon.open ();

OleDbCommand cmd = new OleDbCommand ("{call" + PackageName + ".") + Proname + "(?, {resultset 0, io_cursor})}", Oraclecon);

Cmd. Connection = Oraclecon;

Cmd. Parameters.Add ("RQ", OleDbType.VarChar, 8). Value = "" + RQ + "";

OleDbDataAdapter da = new OleDbDataAdapter (cmd);

DataTable dt = new DataTable ();

DataSet ds = new DataSet ();

Da. Fill (DT);

Oraclecon.close ();

Oraclecon.dispose ();

return DT;

}

}

C # calls a stored procedure method with parameters--oracle "reprint"

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.