C # (in Webapi) gets the stored procedure for Oracle (in PL/SQL) cursor type (used with refcursor)

Source: Internet
Author: User

Requirements: WEBAPI server, access to data through the Oracle database's stored procedures.

To establish a stored procedure in PL/sql: (First and foremost, the entire table is detected)

Create or Replace procedure  is begin Open  for ' SELECT * from wx_sp ' ; End;

C # code: (This is the method called,Out_return , which corresponds to the cursor parameter in the stored procedure, and the type is oracledbtype.refcursor.) sql_wx_sp is the name of the stored procedure)

     PublicDataTable function () {Try{oracleparameter[] par=                {                   NewOracleParameter ("Out_return", Oracledbtype.refcursor)}; par[0]. Direction =ParameterDirection.Output; DataTable result= Dbconnect.getinstance (). Getdatatable ("sql_wx_sp", CommandType.StoredProcedure, par); returnresult; }            Catch(Exception ex) {Throwex; }        }

C # dbhelper code (no dbhelper directly add the database connection string should also do, is significantly a bit amateur, _connstr This is the database connection string )

        Internal DataTable getdatatable (stringparams  oracleparameter[] opar)        {            new  DataTable ();             using New oracledataadapter (SQL, _CONNSTR))            {                DAP. SelectCommand.Parameters.AddRange (Opar);                 = CommandType;                Dap. Fill (DT);            }             return dt;        }

This is a good set, run up, the data is coming (the data type returned here is a DataTable), and then it can be processed.

The code is mainly from: Jory great god, thanks!

Original: http://www.cnblogs.com/jory/p/5362877.html

C # (in Webapi) gets the stored procedure for Oracle (in PL/SQL) cursor type (used with refcursor)

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.