Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>assuming you are using the sourceforge.net/projects/oraclehelpernet "oraclehelper" it is build ontop of ODP (ie Oracle.DataAccess.Client) all you would need to do is: (this is from <a href="http://download.oracle.com/docs/cd/B28359_01/win.111/b28375/featRefCursor.htm" rel="nofollow">http://download.oracle.com/docs/cd/B28359_01/win.111/b28375/featRefCursor.htm</a>)</p> <pre><code>String cmdTxt1 = "begin open :1 for select col1 from test; end;"; OracleCommand cmd = new OracleCommand(cmdTxt1, conn); OracleParameter outRefPrm = cmd.Parameters.Add("outRefPrm", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Output); cmd.ExecuteNonQuery(); // Execute the anonymous PL/SQL block </code></pre> <p>You can also look in %oracle_home%\client_1\odp.net\samples\4\RefCursor for 7 examples (this is when ODP is installed that is)</p> <p>Since the OracleHelper just creates a wrapper around ODP, all you need to do is create the parameter as <strong>OracleDbType.RefCursor</strong> and pass it into the call (be it an execute non-query or datareader or whatnot)</p> <p>now to do this via a procedure:</p> <pre><code>PROCEDURE Get1CurOut(p_cursor1 out refCursor) is BEGIN OPEN p_cursor1 for select * from emp; END Get1CurOut; </code></pre> <p>and to the C#</p> <pre><code>OracleCommand cmd = new OracleCommand("Get1CurOut", con); cmd.CommandType = CommandType.StoredProcedure; // Bind OracleParameter oparam = cmd.Parameters.Add("refcursor", OracleDbType.RefCursor); oparam.Direction = ParameterDirection.Output; try { // Execute command; Have the parameters populated cmd.ExecuteNonQuery(); // Create the OracleDataAdapter OracleDataAdapter da = new OracleDataAdapter(cmd); // Populate a DataSet with refcursor1. DataSet ds = new DataSet(); da.Fill(ds, "refcursor1", (OracleRefCursor)(cmd.Parameters["refcursor1"].Value)); // Print out the field count the REF Cursor Console.WriteLine("Field count: " + ds.Tables["refcursor1"].Columns.Count); } </code></pre> <p>this is lifted (with slight modification) from %oracle_home%\client_1\odp.net\samples\4\RefCursor\sample1.cs</p> <p>here is an (untested) OracleHelper example:</p> <pre><code>string connectionString = "User Id=scott;Password=tiger;Data Source=oracle"; CommandType commandType = CommandType.StoredProcedure; string commandText = "Get1CurOut"; OracleParameter oparam = cmd.Parameters.Add("refcursor", OracleDbType.RefCursor); oparam.Direction = ParameterDirection.Output; OracleDataReader reader; reader = OracleHelper.ExecuteReader(connectionString, commandType, commandText, oparam) ; // show the first row reader.Read(); // Print out SCOTT.EMP EMPNO column Console.WriteLine("EMPNO: {0}", reader.GetDecimal(0)); // Print out SCOTT.EMP ENAME column Console.WriteLine("ENAME: {0}", reader.GetString(1)); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload