SQL ORA-06532: 下标超出限制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24463919/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 02:08:23  来源:igfitidea点击:

ORA-06532: Subscript outside of limit

sqloracleplsql

提问by sunleo

Pleae help me to understand why Second block is throwing error but first block is running.Both places the limit is lesser than the size declared(41).

请帮助我理解为什么第二个块抛出错误但第一个块正在运行。两个地方的限制都小于声明的大小(41)。

Declare
  Type typ_int_array IS VARRAY(41) OF NUMBER;
  v_typ_int_array typ_int_array := typ_int_array(10,20,30,40);
BEGIN
  SYS.DBMS_OUTPUT.PUT_LINE(v_typ_int_array(1));
  v_typ_int_array.extend(6);
  v_typ_int_array(6) := 60;
END;


Declare
  Type typ_int_array IS VARRAY(41) OF NUMBER;
  v_typ_int_array typ_int_array := typ_int_array(10,20,30,40);
BEGIN
  SYS.DBMS_OUTPUT.PUT_LINE(v_typ_int_array(1));
  v_typ_int_array.extend(38);
  v_typ_int_array(38) := 60;    
END;

Exception :

例外 :

**Error :**
Error report -
ORA-06532: Subscript outside of limit
ORA-06512: at line 6
06532. 00000 -  "Subscript outside of limit"
*Cause:    A subscript was greater than the limit of a varray
           or non-positive for a varray or nested table.
*Action:   Check the program logic and increase the varray limit
           if necessary.
10

回答by paxdiablo

The argument to extendis the number of items to addto the array, not the final size.

to 的参数extend是要添加到数组中的项目数,而不是最终大小。

When you add thirty-eight to the original four, you get forty-two, which is definitely greater than 41. Well, it was when I went to school but I'm pretty certain I would have heard about a change like that if they'd enacted it :-)

当你在原来的 4 上加上 38 时,你得到了 42,这绝对大于 41。嗯,那是我上学的时候,但我很确定我会听说这样的变化,如果他们已经制定了它:-)

The first one works because adding six to four only gives you ten, well under the limit of forty-one.

第一个有效,因为将 6 加到 4 只能得到 10,远低于 41 的限制。