0

Can we help me with bug?
In pl/sql I have a bug, but I can not find him ! I think problem with variable ast !

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;
0

2 Answers 2

2

I don't understand why you're going about this this way. In the first place, this:

select min (employee_id)
into min1
from employees;

select max (employee_id)
into max1
from employees;

could be a single query:

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

but I don't see any reason to use PL/SQL here at all. Why not just do this?

UPDATE emp
   SET stars = TRIM(RPAD(' ', ROUND(salary/1000) + 1, '*'));
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much ! You solved problem , which I suffer during the one week ! . Now all code is working !
1

You should set ast to empty string outside the inner loop;

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.