Here is an example that will help.
First a function that return a ref cursor in oracle
create or replace package test_PKG as
function test_rpt (p_testid number) return sys_refcursor;
end test_PKG;
create or replace package body test_PKG as
function test_rpt (p_testid number) return sys_refcursor as
test_rpt_cur sys_refcursor;
begin
open test_rpt_cur for
select 1 as id_info from dual;
return test_rpt_cur;
end test_rpt;
test_PKG
C# code
public Datatable pop_test_rpt (int p_testid_app)
{
using (OracleConnection myconn = new OracleConnection(string_connection_info)
{
const string _default_cursor_name = "1";
myconn.Open();
OracleCommand cmd = new OracleCommand ("test_schema.test_PKG.test_rpt", myconn)
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(_default_cursor_name, OracleDBType.RefCursor, ParamaterDirection.ReturnValue);
cmd.Parameters.Add("p_testid", OracleDBType.Int32).Value = p_testidapp;
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());
myconn.close();
return dt;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…