oracle ORA 06533:下标数不胜数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28945293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ORA 06533: Subscript beyond count
提问by Bhushan
I created below simple block but getting
我在简单的块下面创建了但得到
ORA 06533:Subscript beyond count
ORA 06533:下标数不胜数
error.
错误。
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;
/
回答by Chris Hep
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.
所述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;
/
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-06532: Subscript outside of limit
。您将 VARRAY 限制为 6 个元素,但客户可能拥有更多元素。考虑限制返回、扩展 VARRAY 或实现更动态的集合类型。
回答by Fabio Farath
Your select count(*) into counter from customers;
has more than 6 results this way not able to save into varray(6)
variable.
您以select count(*) into counter from customers;
这种方式有超过 6 个结果无法保存到varray(6)
变量中。
Instead of array, that has a fixed number of elements, you can use nested tableor associative array.
Source: Declare dynamic array in PLSQL
回答by Amir Jafar Jalali
salary_array.extend just extend 1 index. In Your case You must use this syntax for extend all index of varray:
salary_array.extend 只是扩展 1 个索引。在您的情况下,您必须使用此语法来扩展 varray 的所有索引:
salary_array.extend(6);
salary_array.extend(6);
for other case use size of varray insted of 6 .
对于其他情况,使用大小为 6 的 varray insted。
回答by Shankar
Your salary_array
can hold a maximum of 6 customer's salary, but your select count(*) into counter from customers
returns more than 6 records.
您salary_array
最多可以持有 6 个客户的工资,但您select count(*) into counter from customers
返回的记录超过 6 个。
Due to this the array is not able to hold the data or to put in other words, An in-limit subscript was greater than the count of a varray.
由于这个原因,数组无法保存数据或换句话说,一个极限下标大于一个 Varray 的计数。