Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORA-06532: Subscript outside of limit

Tags:

sql

oracle

plsql

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).

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
like image 955
sunleo Avatar asked Jun 28 '14 05:06

sunleo


1 Answers

The argument to extend is the number of items to add to the array, not the final size.

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 :-)

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

like image 126
paxdiablo Avatar answered Oct 06 '22 00:10

paxdiablo