代码的array_var.extend部分需要在循环内部.每次添加时,都会分配新内存.跳过这一步是要求代码存储一些东西而不给它空间.
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;
/
您很可能很快会遇到类似的错误,但是,ORA-06532:下限超出限制.您将VARRAY限制为6个元素,但客户可能会有更多元素.考虑限制返回,扩展VARRAY或实现更动态的集合类型.