我创建了下面简单的块但得到了
ORA 06533:下标超出计数
错误.
有人可以告诉我在下面的代码中我缺少什么.
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
salary_array.extend;
select count(*) into counter from customers;
for i in 1..counter loop
select salary into c_salary from customers where id =i;
salary_array(i):=c_salary;
end loop;
end;
/
Run Code Online (Sandbox Code Playgroud)
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;
/
Run Code Online (Sandbox Code Playgroud)
但是,很快就会遇到类似的错误ORA-06532: Subscript outside of limit.您将VARRAY限制为6个元素,但客户可能会有更多元素.考虑限制返回,扩展VARRAY或实现更动态的集合类型.
小智 1
您salary_array最多可以保存6个客户的工资,但您的select count(*) into counter from customers退货记录超过6条。
因此,数组无法保存数据,或者换句话说,无限下标大于 varray 的计数。
| 归档时间: |
|
| 查看次数: |
62725 次 |
| 最近记录: |