加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

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

发布时间:2020-12-12 06:56:02 所属栏目:MsSql教程 来源:网络整理
导读:我尝试了以下代码的不同方式,比如取出while或if,但是当我把它们放在一起时(if和while),我总是得到错误… undefine numeroset serveroutput onaccept numero prompt 'Type # between 100 and 999: 'declare i number:=1; a char(25); b char(1); c varchar2
我尝试了以下代码的不同方式,比如取出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);

解决方法

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

是因为你声明一个字符串是一个固定的长度(比如说20),并且在你的代码中的某个时刻你给它赋一个长度超过你声明的值的值。

例如:

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

会发生这样的错误

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读