ORA-06533: Subscript beyond count

create or replace procedure test(tab_name in varchar2) as
cursor cur_ref_cons_info(tab_name varchar2) is select b.COLUMN_NAME from user_constraints a,user_cons_columns b where
a.TABLE_NAME=tab_name and a.CONSTRAINT_TYPE='R' and b.CONSTRAINT_NAME=a.R_CONSTRAINT_NAME;
v_index number(1):=0;
type refered_columns is table of user_cons_columns.COLUMN_NAME%type;
v_refered_columns_array refered_columns:=refered_columns();
begin
open cur_ref_cons_info(tab_name);

loop
v_index:=v_index+1;
fetch cur_ref_cons_info into v_refered_columns_array(v_index);

/* if cur_ref_cons_info%rowcount=0 then
dbms_output.put_line('no results');
else
dbms_output.put_line('have results');
end if; */
end loop;

close cur_ref_cons_info;
exception
when others then
dbms_output.put_line(sqlerrm);
end test;

--ORA-06533: Subscript beyond count

ORA-06533: Subscript beyond count
Cause: An in-limit subscript was greater than the count of a varray or too large for a nested table.
Action: Check the program logic and explicitly extend if necessary.

可以考慮在“v_index:=v_index+1;”這句後加一行:
v_refered_columns_array.extend;
試試。
 

 

Index-by-tables,nested table,varray的區別
asktom上有一篇講述這3種類型的區別的帖子,覺得不錯,轉載一下
The major difference between:
(index by tables) and (nested tables/varrays)
is that index by tables are only available in PLSQL, nested tables/varrays are
avaialable in both PLSQL *and* SQL.
Index by tables are basically “sparse” arrays that need no allocation. For
example:
[email protected]> declare
2 type array is table of number index by binary_integer;
3 data array;
4 begin
5 data(1000) := 1;
6 end;
7 /
PL/SQL procedure successfully completed.
Here plsql gladly accepts an entry in the 1,000′th slot — without doing
anything else. There is nothing in slots 1, 2, … 999 (or 1001 or -1, -2,….
)
That array has allocated space for 1 element in the 1,000th position. Nested
tables/varrays do not behave that way:
[email protected]> declare
2 type array is table of number ;
3 data array := array();
4 begin
5 data(1000) := 1;
6 end;
7 /
declare
*
ERROR at line 1:
ORA-06533: Subscript beyond count
ORA-06512: at line 5
Here it is saying “you haven’t allocated me any space up there…”. So, we use
the .extend attribute:
[email protected]> declare
2 type array is table of number ;
3 data array := array();
4 begin
5 data.extend(1000);
6 data(1000) := 1;
7 end;
8 /
PL/SQL procedure successfully completed.
and we can do so.
Note that we do have to allocate 1,000 entries:
[email protected]> declare
2 type array is table of number ;
3 data array := array();
4 begin
5 data.extend(1);
6 data(1000) := 1;
7 end;
8 /
declare
*
ERROR at line 1:
ORA-06533: Subscript beyond count
ORA-06512: at line 6
the nested table/varray type isn’t “sparse” like the index by table.
Day to day, in plsql code, i generally use index by tables exclusively. They
are a little faster, a little more flexible. It is when I need to use the table
type in SQL that I use a nested table (see
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:110612348061
for an example of what I mean by that)….
There are other differences between varrays and nested tables when you use them
for storage in a database table. For example — varrays maintain their “order”.
Nested tables do not. Varrays are stored in lobs — nested tables in separate
tables. There are certain DML operations available for nested tables that are
not avaialable for varrays.
 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章