Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling Oracle stored procedure from C#?

How does one call a stored procedure in oracle from C#?

like image 429
Rohan Avatar asked Oct 15 '10 08:10

Rohan


People also ask

How do you call a procedure in Oracle?

The CALL (PROCEDURE) statement is used to call procedures. A call to a procedure does not return any value. When a procedure with definer's rights is called, the current default schema is set to the eponymously named schema of the definer.

Can we call a procedure from shell script?

Your shell script can invoke SQL*Plus and pass SQL*Plus a . sql file with a script that calls your stored procedure.

Can we call procedure from function in Oracle?

Select (highlight) the code for creating the procedure or function, then click the Run button to create the procedure or function. Select (highlight) the code for calling the procedure or function, then click the Run button to call the procedure or function.

How can we call stored procedure from ADO Net?

Executing a Stored ProcedureSet the CommandText to the name of the stored procedure. Add any required parameters to the Command. Parameters collection. Execute the Command with the ExecuteNonQuery( ) , ExecuteScalar( ) , or ExecuteQuery( ) method (depending on the type of output generated by the stored procedure).


1 Answers

Please visit this ODP site set up by oracle for Microsoft OracleClient Developers: http://www.oracle.com/technetwork/topics/dotnet/index-085703.html

Also below is a sample code that can get you started to call a stored procedure from C# to Oracle. PKG_COLLECTION.CSP_COLLECTION_HDR_SELECT is the stored procedure built on Oracle accepting parameters PUNIT, POFFICE, PRECEIPT_NBR and returning the result in T_CURSOR.

using Oracle.DataAccess; using Oracle.DataAccess.Client;  public DataTable GetHeader_BySproc(string unit, string office, string receiptno) {     using (OracleConnection cn = new OracleConnection(DatabaseHelper.GetConnectionString()))     {         OracleDataAdapter da = new OracleDataAdapter();         OracleCommand cmd = new OracleCommand();         cmd.Connection = cn;         cmd.InitialLONGFetchSize = 1000;         cmd.CommandText = DatabaseHelper.GetDBOwner() + "PKG_COLLECTION.CSP_COLLECTION_HDR_SELECT";         cmd.CommandType = CommandType.StoredProcedure;         cmd.Parameters.Add("PUNIT", OracleDbType.Char).Value = unit;         cmd.Parameters.Add("POFFICE", OracleDbType.Char).Value = office;         cmd.Parameters.Add("PRECEIPT_NBR", OracleDbType.Int32).Value = receiptno;         cmd.Parameters.Add("T_CURSOR", OracleDbType.RefCursor).Direction = ParameterDirection.Output;          da.SelectCommand = cmd;         DataTable dt = new DataTable();         da.Fill(dt);         return dt;     } } 
like image 65
hyperkittie Avatar answered Sep 30 '22 09:09

hyperkittie