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

标签 sql oracle if-statement plsql while-loop

我尝试了以下代码的不同方式,例如取出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;
/

错误:
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 的回答,这就是关键。

最佳答案

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



是因为您将字符串声明为固定长度(比如 20),并且在代码中的某个点为它分配了一个长度超过您声明的值的值。

例如:
myString VARCHAR2(20);
myString :='abcdefghijklmnopqrstuvwxyz'; --length 26

会触发这样的错误

关于sql - ORA-06502 : PL/SQL: numeric or value error: character string buffer too small,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18731560/

相关文章:

SQL - 使用 GROUP BY 时以逗号分隔的多个值

sql - 使用 Django 时神秘的 PostgreSQL 日志条目

node.js - 如果我们不知道存储过程绑定(bind)参数,如何在node-oracledb中执行 "Stored Procedure"查询?

javascript - 将 if 和 else if 函数与选择输入一起使用(根据公里和英里转换结果)

java - 当收到 NumberFormatException 时,如何阻止或重做 SWING 输入?

Java if 条件为空验证

sql - SQL Server 中的月和年筛选器

mysql - 是否可以使用 "delete from"语句合并两条记录?

sql - 尝试插入 View 时无法修改映射到非键保留表错误的列

linux - 安装 OP5 Monitor/Nagios :