我创建了下面简单的块但得到了
ORA 06533:Subscript beyond count
错误.
有人可以告诉我在下面的代码中我缺少什么.
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部分需要在循环内部.每次添加时,都会分配新内存.跳过这一步是要求代码存储一些东西而不给它空间.
原文链接:https://www.f2er.com/oracle/205039.htmldeclare 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或实现更动态的集合类型.