create or replace procedure Create_Barcodes as
--用于生成条码值bar varchar(10);
i number(10);
begin
     i:=1;
     while i<10000 loop
     
         bar:=to_char(i,'9999999999');--报错:“ORA-06502:   PL/SQL:   数字或值错误   :   字符串缓冲区太小”
         bar:=TRANSLATE(bar , ' ' , '0');
     
         insert into sys_barcode
           (barcode, is_used)
         values
           (bar, 0);
   
         i :=i+1;
     end loop;       commit;
end;

解决方案 »

  1.   

    把 bar varchar(10) 调大试试
      

  2.   

    ORA-06502 PL/SQL: numeric or value errorstring  Cause  An arithmetic, numeric, string, conversion, or constraint error occurred. For example, this error occurs if an attempt is made to assign the value NULL to a variable declared NOT NULL, or if an attempt is made to assign an integer larger than 88 to a variable declared NUMBER(2). 
     
    Action Change the data, how it is manipulated, or how it is declared so that values do not violate constraints.  
      

  3.   

    上面不对,给你这个网站,估计会有帮助 http://loyou.cnblogs.com/
      

  4.   

    问题是我定义了十位的,为什么要我减小长度啊!减少了长度确实可以执行。表sys_barcode的字段本来定义的就是NVARCHAR2(10),为什么不能插入十位长的啊?
      

  5.   

    因为转换时前面还有一位符号位,trim一下就可以了.
      

  6.   

    楼上的解决方法只是个敷衍的方法(trim),应该bar:=to_char(i, 'FM9999999999 ');就没问题了