[英]ORA-06502: PL/SQL: numeric or value error: character string buffer too small
I tried the following code different ways, like by taking out the while or the if, but when I put both together (if and while), I always get the error at the end...我尝试了以下代码的不同方式,例如取出while或if,但是当我将两者放在一起(if和while)时,我总是在最后得到错误......
undefine numero
set serveroutput on
accept numero prompt 'Type # between 100 and 999: '
declare
i number:=1;
a char(25);
b char(1);
c varchar2(10);
d number;
begin
c := №
d := length(c);
b := substr(c, i, 1);
while i <= d loop
if b = '1' then
a:= a||'one ';
end if;
i := i+1;
end loop;
dbms_output.put_line('The number is '||a);
end;
/
ERROR:错误:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 13
06502. 00000 - "PL/SQL: numeric or value error%s"
FIXED by changing how I declared the variable "a" to:通过将变量“a”的声明方式更改为:
a varchar2(2000);
*Notice that here, the significant change is to use VARCHAR2 instead of CHAR (not the bigger length). *请注意,这里的重大变化是使用 VARCHAR2 而不是 CHAR(不是更大的长度)。 According to @user272735 's answer, that's the key.
根据@user272735 的回答,这就是关键。
PL/SQL: numeric or value error: character string buffer too small
PL/SQL:数字或值错误:字符串缓冲区太小
is due to the fact that you declare a string to be of a fixed length (say 20), and at some point in your code you assign it a value whose length exceeds what you declared.是因为您将字符串声明为固定长度(比如 20),并且在代码中的某个点为它分配了一个长度超过您声明的值的值。
for example:例如:
myString VARCHAR2(20);
myString :='abcdefghijklmnopqrstuvwxyz'; --length 26
will fire such an error会触发这样的错误
CHAR
is a fixed-length data type that uses as much space as possible. CHAR
是一种固定长度的数据类型,它使用尽可能多的空间。 So a:= a||'one ';
所以
a:= a||'one ';
will require more space than is available.将需要比可用空间更多的空间。 Your problem can be reduced to the following example:
您的问题可以简化为以下示例:
declare
v_foo char(50);
begin
v_foo := 'A';
dbms_output.put_line('length of v_foo(A) = ' || length(v_foo));
-- next line will raise:
-- ORA-06502: PL/SQL: numeric or value error: character string buffer too small
v_foo := v_foo || 'B';
dbms_output.put_line('length of v_foo(AB) = ' || length(v_foo));
end;
/
Never use char
.永远不要使用
char
。 For rationale check the following question (read also the links):有关基本原理,请检查以下问题(另请阅读链接):
This may also happen if you have a faulty or accidental equation in your csv file.如果您的 csv 文件中有错误或意外的方程,也可能发生这种情况。 ie - One of the cells in your csv file starts with an equals sign (=) (An excel equation) which will, in turn throw an error.
即 - csv 文件中的一个单元格以等号 (=)(一个 excel 方程)开头,这反过来会引发错误。 If you fix, or remove this equation by getting rid of the equals sign, it should solve the ORA-06502 error.
如果您通过去掉等号来修复或删除此等式,它应该解决 ORA-06502 错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.