2

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());
}
8
  • please try to you change 250 to 255 for x varchar2(250);, and look whether the error persists ... Commented Dec 21, 2017 at 8:13
  • Possible duplicate of ORA-06502: PL/SQL: numeric or value error: character string buffer too small Commented Dec 21, 2017 at 8:14
  • @BarbarosÖzhan still not working after changing 250 to 255 Commented Dec 21, 2017 at 8:22
  • You are setting the size to 40000 when you add x as a parameter and afterwards you reset that size to 255. Why? Commented Dec 21, 2017 at 8:23
  • @bradbury9 nops i have already check it before posting this Commented Dec 21, 2017 at 8:23

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.