简体   繁体   中英

Character string buffer too small error while calling Oracle function using C#

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());
}

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM