C # Calls the simplest instance of an Oracle stored procedure

Source: Internet
Author: User
Tags oracleconnection
oracle| Stored Procedures

Oracle Side
1. Creating Oracle Process Storage
Create or Replace procedure Proce_test (paramin in Varchar2,paramout out varchar2,paraminout into out varchar2)
As
Varparam VARCHAR2 (28);
Begin
Varparam:=paramin;
paramout:=varparam| | Paraminout;
End
2. Test process Storage
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 # Aspect
Referencing 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"; Connecting to a 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 declarations for stored procedures
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 stored procedure name
Cmd.commandtype=commandtype.storedprocedure;
foreach (oracleparameter parameter in parameters)
{
Cmd. Parameters.Add (parameter);
}
Cmd. ExecuteNonQuery ();//Execute stored Procedure
}
}
}
Test results: 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.