C # The simplest example of calling an oracle Stored Procedure

Source: Internet
Author: User
Tags oracleconnection
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.