ORA-06502: PL/SQL: numeric or value error: character string buffer too small(ORA-06502:PL/SQL:数字或值错误:字符串缓冲区太小)
问题描述
我尝试了以下代码的不同方式,例如取出 while 或 if,但是当我将两者放在一起(if 和 while)时,我总是在最后得到错误...
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...
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;
/
错误:
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"
通过将我声明变量a"的方式更改为:
a varchar2(2000);
*注意,这里的重大变化是使用 VARCHAR2 而不是 CHAR(不是更大的长度).根据@user272735 的回答,这就是关键.
*Notice that here, the significant change is to use VARCHAR2 instead of CHAR (not the bigger length). According to @user272735 's answer, that's the key.
推荐答案
PL/SQL:数字或值错误:字符串缓冲区太小
PL/SQL: numeric or value error: character string buffer too small
是因为您将字符串声明为固定长度(比如 20),并且在代码中的某个点为它分配了一个长度超过您声明的值的值.
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.
例如:
myString VARCHAR2(20);
myString :='abcdefghijklmnopqrstuvwxyz'; --length 26
会触发这样的错误
这篇关于ORA-06502:PL/SQL:数字或值错误:字符串缓冲区太小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ORA-06502:PL/SQL:数字或值错误:字符串缓冲区太小
基础教程推荐
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
