【问题标题】:ORA-06502: PL/SQL: numeric or value error: character string buffer too small.at line 23ORA-06502: PL/SQL: 数字或值错误: 字符串缓冲区太小。在第 23 行
【发布时间】:2015-05-16 10:48:14
【问题描述】:

我们可以帮我解决错误吗?
在 pl/sql 我有一个错误,但我找不到他! 我认为变量 ast 有问题!

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

declare 

ast varchar2(50);
slr emp.salary%type;
max1 emp.employee_id%type;
min1 emp.employee_id%type;

begin 
select min (employee_id)
into min1
from employees;

select max (employee_id)
into max1
from employees;

for   i in min1..max1 
 loop
         select (round (salary /1000))      
    into slr
    from employees
    where employee_id = i ;

      for i in 1..slr loop
        ast := ast || '*' ;
        end loop;
        update emp set stars = ast
        where employee_id=i;
        commit;
end loop;
end;

【问题讨论】:

    标签: oracle plsql ora-06502


    【解决方案1】:

    我不明白你为什么要这样。首先,这是:

    select min (employee_id)
    into min1
    from employees;
    
    select max (employee_id)
    into max1
    from employees;
    

    可以是单个查询:

    SELECT MIN(employee_id), MAX(employee_id) INTO min1, max1
      FROM employees;
    

    但我看不出有任何理由在这里使用 PL/SQL。为什么不这样做呢?

    UPDATE emp
       SET stars = TRIM(RPAD(' ', ROUND(salary/1000) + 1, '*'));
    

    【讨论】:

    • 非常感谢!你解决了我在一周内遇到的问题! .现在所有代码都可以工作了!
    【解决方案2】:

    你应该设置 ast 为空字符串 在内循环之外;

     for   i in min1..max1 
       loop
       ast:='';
       ...
    

    【讨论】:

      猜你喜欢
      • 2013-09-14
      • 2011-03-31
      • 1970-01-01
      • 2011-11-25
      • 1970-01-01
      • 2018-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多