Oracle.Dataaccess 错误 ORA-06502:PL/SQL:数字或值错误:字符串缓冲区太小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2077552/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 19:49:13  来源:igfitidea点击:

Oracle.Dataaccess error ORA-06502: PL/SQL: numeric or value error: character string buffer too small

.netoracledata-access

提问by moejoe11

I am invoking a stored proc from .NET app. The proc returns an out parameter of type Varchar2. To fet ch the out parameter I am passing the parameter to the command as OracleParameter:

我正在从 .NET 应用程序调用存储过程。proc 返回一个 Varchar2 类型的 out 参数。为了获取输出参数,我将参数作为 OracleParameter 传递给命令:

parm12 = new OracleParameter("testkey"
                              , OracleDbType.Varchar2
                              , out2
                              , ParameterDirection.Output);

When I execute the proc I am receiving an error

当我执行 proc 时,我收到一个错误

PL/SQL: numeric or value error: character string buffer too small.

回答by moejoe11

Found the answer.

找到了答案。

For the OUT parameter i declared the size to max of varchar - 32767 and it started to work.

对于 OUT 参数,我声明了 varchar 的最大值 - 32767,它开始工作。

To simplify, the stored proc returns a parameter OUT of type VARCHAR2. But to consume that output from .NET i was passing VARCHAR2 without any size. So the buffer space allocated to recieve the reurn value was 0 bytes. When the proc returns the value more than allocated buffer which is 0 bytes it errors out.

为简化起见,存储过程返回一个 VARCHAR2 类型的参数 OUT。但是为了使用 .NET 的输出,我传递了没有任何大小的 VARCHAR2。所以分配给接收reurn值的缓冲区空间是0字节。当 proc 返回的值超过分配的 0 字节缓冲区时,它会出错。

So i specified the max of VARCHAR2-32767 in the C# code and it started to work :).

所以我在 C# 代码中指定了 VARCHAR2-32767 的最大值,它开始工作:)。

回答by APC

In your code out2is the argument which specifies the length of the parameter. So check the value in that variable, because apparently it is not long enough for procedure's output.

在您的代码中out2是指定参数长度的参数。所以检查该变量中的值,因为显然它对于过程的输出来说不够长。