Friday, March 29, 2013

oracle SUBSCRIPT_OUTSIDE_LIMIT exception handling

ORACLE SUBSCRIPT_OUTSIDE_LIMIT exception handling


  PL/SQL  Subscript_outside_limit  exception occurs when you access an VARRAY with lower index is 0(default is 1) and Upper Index is more than number of elements.



declare
 type varray_type is VARRAY(5) OF Number;
 depts varray_type := varray_type(10,20,30);
begin
dbms_output.put_line(depts(0)); --throws subscript_outside_limit exception
end;


SQL> /
declare
*
ERROR at line 1:
ORA-06532: Subscript outside of limit
ORA-06512: at line 5


Handling  Subscript_outside_error exception

declare
 type varray_type is VARRAY(5) OF Number;
 depts varray_type := varray_type(10,20,30);
begin
dbms_output.put_line(depts(0));
exception
    when subscript_outside_limit then
       dbms_output.put_line(' Index range must start with 1 and should end with max number of elements in an array');
end;



Tags:oracle SUBSCRIPT_OUTSIDE_LIMIT exception handling,Handling  Subscript_outside_error exception,VARRAY in PL/SQL,Creating VARRAY in PL/SQL block,Accessing VARRAY in PL/SQL block,VARRAY STARING INDEX,VARRAY MAX INDEX,
ORA-06532: Subscript outside of limit

No comments:

Post a Comment