2015-03-13 56 views
0

我們可以幫助我解決錯誤嗎?
在pl/sql中有一個錯誤,但我找不到他! 我覺得可變的ast問題!ORA-06502:PL/SQL:數值或數值錯誤:字符串緩衝區太小small.at第23行

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

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; 

回答

1

您應該設置AST以內環外空字符串 ;

for i in min1..max1 
    loop 
    ast:=''; 
    ... 
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, '*')); 
+0

非常感謝!你解決了我在一週內遭受的問題! 。現在所有的代碼都在工作! – user3528511 2015-03-14 03:06:57

相關問題