I am using a product that provides Oracle API-based database APIs, and I can call functions through ODP.NET in general. However, I cannot figure out how to call a function that includes Ref Cursor as an Out parameter. All the samples I have found so far call a procedure with an Out parameter or a parameter using Ref Cursor as the return value. I tried to define the parameters in the same way, but I continue to receive an error message if the wrong parameter number or type is specified.
Here is the function title (obviously confusing):
FUNCTION GetXYZ( uniqueId IN somepackage.Number_Type, resultItems OUT somepackage.Ref_Type) RETURN somepackage.Error_Type;
These are the type definitions in "somepackage":
SUBTYPE Number_Type IS NUMBER(13); TYPE Ref_Type IS REF CURSOR; SUBTYPE Error_Type IS NUMBER;
And this is the code I tried:
string sql = "otherpackage.GetXYZ"; var getXYZCmd = OracleCommand oracleConnection.CreateCommand(sql); getXYZCmd.CommandType = CommandType.StoredProcedure; getXYZCmd.Parameters.Add("uniqueId", OracleDbType.Int32).Value = uniqueExplosionId; getXYZCmd.Parameters.Add("resultItems", OracleDbType.RefCursor).Direction = ParameterDirection.Output; getXYZCmd.Parameters.Add("return_value", OracleDbType.Int32).Direction = ParameterDirection.ReturnValue;
I tried the following different ways to call a function (of course, only one at a time):
var result = getXYZCmd.ExecuteNonQuery(); var reader = getXYZCmd.ExecuteReader(); var scalarResult = getXYZCmd.ExecuteScalar();
But each of them crashes with an error message:
Oracle.DataAccess.Client.OracleException: ORA-06550: line 1, column 15: PLS-00306: wrong number or types of arguments in call to 'GETXYZ' ORA-06550: line 1, column 15: PLS-00306: wrong number or types of arguments in call to 'GETXYZ' ORA-06550: line 1, column 7: PL/SQL: Statement ignored.
So is it even possible to call a function with the Ref cursor as an Out parameter from C # with ODP.NET? I can call a function with the same structure with the Varchar2-Out parameter instead of the Ref Cursor without any problems ...
Btw, I am using ODP.NET version 2.112.2.0 from C # .NET 3.5 in Visual Studio 2008.
Thanks in advance for your help!