How does one call a stored procedure in oracle from C#?
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.
Your shell script can invoke SQL*Plus and pass SQL*Plus a . sql file with a script that calls your stored procedure.
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.
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).
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; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With