加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle – ORA 06533:下标超出计数

发布时间:2020-12-12 13:11:44 所属栏目:百科 来源:网络整理
导读:我创建了下面简单的块但得到了 ORA 06533:Subscript beyond count 错误. 有人可以告诉我在下面的代码中我缺少什么. declare type salaryvarray is varray(6) of customers.salary%type; salary_array salaryvarray:=salaryvarray(); c_salary customers.sala
我创建了下面简单的块但得到了

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部分需要在循环内部.每次添加时,都会分配新内存.跳过这一步是要求代码存储一些东西而不给它空间.
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或实现更动态的集合类型.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读