简体   繁体   English

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

[英]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.

相关问题 ORA-06502:PL / SQL:数字或值错误:Oracle SQL查询中的字符串缓冲区太小 - ORA-06502: PL/SQL: numeric or value error: character string buffer too small in Oracle sql query Oracle数据库错误:ORA-06502:PL / SQL:数字或值错误:字符串缓冲区太小 - Oracle Database Error: ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06502:PL/SQL:数字或值错误:字符串缓冲区太小,只有三个数字 - ORA-06502: PL/SQL: numeric or value error: character string buffer too small only three numbers ORA-06502: PL/SQL: 数字或值错误: 字符串缓冲区太小: 构建时 model - ORA-06502: PL/SQL: numeric or value error: character string buffer too small: When building a model Oracle SQL 错误代码 ORA-06502: PL/SQL: numeric or value error: string buffer too small at line 18 - Oracle SQL Error Code ORA-06502: PL/SQL: numeric or value error: character string buffer too small at line 18 tab_to_string [错误]执行(37:13):ORA-06502:PL / SQL:数字或值错误:字符串缓冲区太小 - tab_to_string [Error] Execution (37: 13): ORA-06502: PL/SQL: numeric or value error: character string buffer too small 字符串缓冲区太小ORA-06502 - character string buffer too small ORA-06502 SQL错误:ORA-06502:PL / SQL:数字或值错误 - SQL Error: ORA-06502: PL/SQL: numeric or value error 奇怪的ORA-06502:PL / SQL:数字或值错误 - Strange ORA-06502: PL/SQL: numeric or value error ORA-06502: PL/SQL: 连接时出现数字或值错误 - ORA-06502: PL/SQL: numeric or value error when concatenating
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM