0

我们可以帮我解决错误吗?
在 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;
4

2 回答 2

2

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

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, '*'));
于 2015-03-13T20:31:11.170 回答
1

您应该将 ast 设置为内部循环之外的空字符串;

 for   i in min1..max1 
   loop
   ast:='';
   ...
于 2015-03-13T20:23:08.190 回答