C # The simplest example of calling an oracle Stored Procedure

Source: Internet
Author: User

 

Oracle
1. Create an Oracle Stored Procedure
Create or replace procedure proce_test (paramin in varchar2, paramout out varchar2, paraminout in out varchar2)
As
Varparam varchar2 (28 );
Begin
Varparam: = paramin;
Paramout: = varparam | paraminout;
End;
2. Test the Stored Procedure
Declare
Param_out varchar2 (28 );
Param_inout varchar2 (28 );
Begin
Param_inout: = ff;
Proce_test (dd, param_out, param_inout );
Dbms_output.put_line (param_out );
End;

C #
Reference Oracle components
Using System;
Using System. Data;
Using System. Data. OracleClient;

Namespace WebApplication4
{
Public class OraOprater
{
Private OracleConnection conn = null;
Private OracleCommand cmd = null;
Public OraOprater ()
{
String mConn = "data source = ora9i.ora.com; user id = ora; password = ora"; // connect to the database
Conn = new OracleConnection (mConn );
Try
{
Conn. Open ();
Cmd = new OracleCommand ();
Cmd. Connection = conn;
}
Catch (Exception e)
{
Throw e;
}
}

Public string SpExeFor (string m_A, string m_ B)
{
// Parameter declaration of Stored Procedure
OracleParameter [] parameters = {
New OracleParameter ("paramin", OracleType. VarChar, 20 ),
New OracleParameter ("paramout", OracleType. VarChar, 20 ),
New OracleParameter ("paraminout", OracleType. VarChar, 20)
};
Parameters [0]. Value = m_A;
Parameters [2]. Value = m_ B;
Parameters [0]. Direction = ParameterDirection. Input;
Parameters [1]. Direction = ParameterDirection. Output;
Parameters [2]. Direction = ParameterDirection. InputOutput;
Try
{
RunProcedure ("proce_test", parameters );
Return parameters [1]. Value. ToString ();
}
Catch (Exception e)
{
Throw e;
}
}

Private void RunProcedure (string storedProcName, OracleParameter [] parameters)
{
Cmd. CommandText = storedProcName; // declare the name of the stored procedure
Cmd. CommandType = CommandType. StoredProcedure;
Foreach (OracleParameter parameter in parameters)
{
Cmd. Parameters. Add (parameter );
}
Cmd. ExecuteNonQuery (); // execute the Stored Procedure
}
}
}
Test result: ddff


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.