Domanda

Given a custom cursor type:

create or replace 
PACKAGE                               Types AS
  TYPE cursor_type IS REF CURSOR;
END Types;

And a stored procedure that returns this type:

create or replace 
procedure TheProcedure
(RS OUT someSchema.TYPES.CURSOR_type, someCode number)
is 
begin
open RS for 
    --A custom query
     select 
            someTable.field,
            anotherTable.field,

      from someTable,
           anotherTable,
       where 
           anotherTable.code = someTable.code
           AND someTable.someFK = someCode;
end TheProcedure;

I need to retrieve all data using ODP.Net (Oracle.DataAccess.Client)

string connectionString = ConfigurationManager.ConnectionStrings["cnx"].ConnectionString;
using (OracleConnection conn = new OracleConnection(connectionString))
{
    conn.Open();

    OracleCommand cmd = new OracleCommand();
    cmd.Connection = conn;

    cmd.CommandText = "ASCHEMA.TheProcedure";
    cmd.CommandType = System.Data.CommandType.StoredProcedure;

    OracleParameter prmCursor = cmd.Parameters.Add("RS", OracleDbType.RefCursor);
    prmCursor.Direction = ParameterDirection.Output;
    cmd.Parameters.Add("someCode", OracleDbType.NVarchar2).Value = 19685;
    //the integrity of the sql query was verified
    cmd.ExecuteNonQuery();
    OracleDataReader anotherReader = ((OracleRefCursor)prmCursor.Value).GetDataReader();

    while (anotherReader.Read())
    {
        var some = !anotherReader.IsDBNull(0) ? anotherReader.GetValue(0) : 0;
    }
}

But the reader anotherReader never returns data, I think that I need to do some special stuff for the User Defined Type TYPE.cursor_type, but how?

Thanks in advance.

È stato utile?

Soluzione

Do you really need to make it a User Defined Type? Just use SYS_REFCURSOR instead. Here is some example code:

http://www.oracle.com/technetwork/articles/dotnet/williams-refcursors-092375.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top