I’m trying to execute the following stored procedure in .net 4.5
PROCEDURE my_procedure (
a_cursor OUT t_cursor,
return_value OUT VARCHAR2,
a_type VARCHAR2,
a_time DATE,
a_id VARCHAR2,
a_arg1 VARCHAR2,
a_from VARCHAR2,
a_gl2 VARCHAR2,
a_arg2 DATE DEFAULT NULL,
a_templ VARCHAR2 DEFAULT NULL
)
Most of these arguments can be null. In toad I can execute it with:
BEGIN package.my_procedure( :c, :out, 'arg', '', '123' , '', '', '', '', ''); END;
In C# I’m trying the following:
object[] parameters = {
new OracleParameter("arg1", arg1),
new OracleParameter("arg", "arg"),
new OracleParameter("empti", ""),
new OracleParameter("out", OracleDbType.Varchar2, ParameterDirection.Output),
new OracleParameter("c", OracleDbType.RefCursor, ParameterDirection.Output)
};
const string sql = "BEGIN package.my_procedure
(:c, :out, :arg, :empti, :arg1 , :empti, :empti, :empti, :empti, :empti); END;";
res = _projectRepository.ExecuteStoredProcedure(sql, parameters);
And I get the following error
Test method Tests.repository.RepositoryTests.TestMethod1 threw exception:
Oracle.DataAccess.Client.OracleException: ORA-06550:
line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'my_procedure'ORA-06550:
line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'my_procedure'ORA-06550:
line 1, column 7:
PL/SQL: Statement ignored
I’ve tried with and without the optional parameters and with/without the return_value/:out parameter.
I am using the Oracle.DataAccess provider v. 4.112.3.0. It works with other stored procedures that does not have that many parameters / only one out parameter (cursor).
EDIT: I found one error, i need to have the output parameters first in the parameter array;
new OracleParameter("c", OracleDbType.RefCursor, ParameterDirection.Output),
new OracleParameter("out", OracleDbType.Varchar2, ParameterDirection.Output),
new OracleParameter("arg1", "arg1"),
new OracleParameter("empti", ""),
new OracleParameter("arg", arg),
};
Now i am getting the error:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
seems like a database error, but looks strange since i can execute the same command from toad without getting the error.
When using
VARCHAR2as anOUPUTyou need to provide the size of the character buffer. The constructor overloads won’t help here though, you’ll need to create the variable by hand to set the required properties.Original
I’ll leave the original answer in tact, as it took care of the first version of the question.
The error provided is correct, you’re not providing the right number of parameters in your call. Let’s look at the original working code that Toad for Oracle can use and map them to the parameter names:
Notice that in Toad for Oracle you’re even providing values for the parameters declared as
DEFAULT NULL(which isn’t a problem).If you look at your parameter list you’ll see that you’re providing bindings for
arg1,arg,empti,out, andp. You position these to match up as follows:Oracle is complaining that the number of parameters didn’t match, and that’s because you’re declaring your reference cursor parameter as
pand not asc. You need to either update theOracleParamterto the name ofcor change the PL/SQL being executed to:pfor the first parameter.