oracle - Get 'PL\SQL Table' returned from a function with OracleCommand in C# -
i'm new using oraclecommand
in c# return results oracles procedures\functions, i've been able of storedprocedure executions working i'm in need of advise on following.
below function returns table created off record type
create or replace function return_table return t_nested_table v_ret t_nested_table; begin v_ret := t_nested_table(); v_ret.extend; v_ret(v_ret.count) := t_col(1, 'one'); v_ret.extend; v_ret(v_ret.count) := t_col(2, 'two'); v_ret.extend; v_ret(v_ret.count) := t_col(3, 'three'); return v_ret; end return_table;
the type created follows
create or replace type t_col object ( number, n varchar2(30) );
the table t_col record
create or replace type t_nested_table table of t_col;
now when wanted execute function in c#, tried following realised oracledbtype has no enum pl\sql table.
using (oracleconnection conn = new oracleconnection(connection)) using (oraclecommand cmd = new oraclecommand()) { cmd.connection = conn; cmd.bindbyname = true; cmd.commandtext = "return_table"; cmd.commandtype = commandtype.storedprocedure; cmd.parameters.add("\"v_ret\"", oracledbtype.object, dbnull.value, parameterdirection.returnvalue); conn.open(); try { cmd.executenonquery(); } catch (exception ex) { console.writeline(ex.message); } }
but throws error:
invalid parameter binding parameter name: "v_ret"
i've tried other ways far nothing has worked.
i'm hoping there way fix in c# code because there allot of existing function won't able edit.
i had @ similar questions mine not able fine answer them.
this c# code may useful you, worked me own defined oracle type:
using (oraclecommand cmd = new oraclecommand()) { cmd.connection = conn; cmd.commandtext = "select * table(return_table())"; cmd.commandtype = commandtype.text; conn.open(); oracledatareader rdr = cmd.executereader(); while (rdr.read()) { console.writeline(rdr.getoracledecimal(0)); console.writeline(rdr.getoraclestring(1)); } conn.close(); }
Comments
Post a Comment