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:
ops$tkyte@ORA817DEV.US.ORACLE.COM> 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:
ops$tkyte@ORA817DEV.US.ORACLE.COM> 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:
ops$tkyte@ORA817DEV.US.ORACLE.COM> 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:
ops$tkyte@ORA817DEV.US.ORACLE.COM> 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.
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值