Reputation: 21
plsql numeric value error while calling the oracle function from C# - please tell me how to remove that error.
PL/SQL: numeric or value error: character string buffer too small
Code:
create or replace function testdotnet(h1 varchar2)
return varchar2
as
x varchar2(250);
begin
select 'hello' into x from dual;
return x;
end;
C# code:
string CommandStr = "APPS.testdotnet";
using (OracleConnection conn = new OracleConnection("User Id=apps;Password=***;Data Source=***"))
using (OracleCommand cmd = new OracleCommand(CommandStr, conn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("h1", OracleDbType.Varchar2).Value = "aaa";
cmd.Parameters.Add("x", OracleDbType.Varchar2, 40000).Direction = ParameterDirection.ReturnValue;
cmd.Parameters["x"].Size = 255;
cmd.Parameters["h1"].Size = 255;
conn.Open();
cmd.ExecuteNonQuery();
Response.Write( cmd.Parameters["x"].Value.ToString());
}
Upvotes: 2
Views: 1855
Reputation: 11
My stored procedure had "keys"
as an output parameter in definition.
command.Parameters.Add("keys", OracleDbType.Varchar2, 32767).Direction = ParameterDirection.Output;
That fixed it for me, passing the size of output varchar2 variable along with the type.
I hope this helps someone looking for the solution of this error.
Upvotes: 0
Reputation: 59456
Maximum size of VARCHAR2
is 32,767 bytes, 40,000 is not possible.
Change
cmd.Parameters.Add("x", OracleDbType.Varchar2, 40000).Direction = ParameterDirection.ReturnValue;
to
cmd.Parameters.Add("x", OracleDbType.Varchar2, 32767).Direction = ParameterDirection.ReturnValue;
or use CLOB
if you need bigger data.
Upvotes: 3