ORA 06533:下标无数 [英] ORA 06533: Subscript beyond count
问题描述
我在下面的简单代码块中创建了,但得到了
I created below simple block but getting
ORA 06533:下标超出计数
ORA 06533:Subscript beyond count
错误.
有人可以告诉我下面的代码中我缺少什么吗?
Can someone please tell me what I am missing in below code.
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;
/
推荐答案
代码的array_var.extend
部分必须位于循环内.每次添加时,您都在分配新的内存.跳过此步骤就是要求代码存储某些内容而不给其空间.
The array_var.extend
portion of the code needs to be inside the loop. Each time you add to it, you are allocating new memory. Skipping this step is asking the code to store something without giving it space.
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: Subscript outside of limit
.您将VARRAY限制为6个元素,但客户可能拥有更多元素.考虑限制收益,扩大VARRAY或实现更具动态性的集合类型.
You will very likely run into a similar error soon, however, ORA-06532: Subscript outside of limit
. You limit your VARRAY to 6 elements, but customers could potential have more. Consider limiting the return, expanding the VARRAY or implementing a more dynamic collection type.
这篇关于ORA 06533:下标无数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!