Part of the array_var.extend code must be inside the loop. Each time you add to it, you allocate a new memory. Skipping this step requires the code to store something without specifying it.
declare type salaryvarray is varray(6) of customers.salary%type; salary_array salaryvarray:=salaryvarray(); c_salary customers.salary%type; i integer(2); counter number(2); begin select count(*) into counter from customers; for i in 1..counter loop salary_array.extend; -- Extend for each value. select salary into c_salary from customers where id =i; salary_array(i):=c_salary; end loop; end; /
Soon you are likely to encounter a similar error, ORA-06532: Subscript outside of limit . You limit VARRAY to 6 elements, but there may be more potential customers. Consider a return restriction, a VARRAY extension, or the introduction of a more dynamic collection type.
source share