PL/SQL中集合出现“ORA-06533:下表超出数量”的问题解决
2013-02-24 18:54
531 查看
VARRAY是在Oracle8G的时候引入的一个类型,是一种密集填充数组,更容易被理解成为一个传统的数组。在创建这些数组的时候,都有一个尺寸,需要非常注意的是VARRAY的下表是从1开始的,在其他很多变成语言中,数组的下表都是从0开始的,比如J***A。在实际的使用中,初学者经常会出现如下的错误提示:
ORA-06533:下表超出数量
例如下面的代码就会出现该错误:
这个错误的原因是什么呢?我们定义了一个为空的VARRAY,在第一个J循环的时候,将1赋值给V_NUM_ARRAY(1),但是因为实际上,该集合变量并没有存储空间,因此PL/SQL就会报一个“下表超出数量”的错误。
如何去解决这个问题呢?查阅Oracle 的MOS 找到了如下描述:
use a constructor. For more information, see "Collection Constructors".)
The
elements to the collection.
of the ith element to the collection.
Note:
the only form that you can use for a collection whose elements have the
for it, then
Example 5-20 declares a nested table variable, initializing it with three elements; appends two copies of the first
element; deletes the fifth (last) element; and then appends one null element. Because
the nested table variable after initialization and after the
defined inExample 5-6.
Example 5-20 EXTEND Method with Nested Table
Result:
上面的大意是:
EXTEND方法为VARRAY或者NESTED TABLE集合中的一个或者多个新元素分配存储空间。有两个可以选择的选项,默认情况下,是它在向集合添加值之前的时候,为该值分配存储空间。他的两个参数的意思分别是,第一个参数是增加多少个元素的空间,第二个参数的意思是引用集合中已经存在的元素的索引,该元素就会被复制到新的元素上。
作者 陈字文(热衷于PM\ORACLE\J***A等,欢迎同行交流):ziwen#163.com 扣扣:4零9零2零1零零
上面出错的代码修改为如下可以正常运行了:
ORA-06533:下表超出数量
例如下面的代码就会出现该错误:
DECLARE TYPE NUM_VARRAY IS VARRAY(100) OF NUMBER NOT NULL; V_NUM_VARRAY NUM_VARRAY:=NUM_VARRAY(); BEGIN FOR J IN 1 .. 100 LOOP V_NUM_VARRAY(J) := J; END LOOP; FOR I IN 1 .. V_NUM_VARRAY.COUNT LOOP DBMS_OUTPUT.PUT_LINE(TO_CHAR(V_NUM_VARRAY(I))); END LOOP; END;
这个错误的原因是什么呢?我们定义了一个为空的VARRAY,在第一个J循环的时候,将1赋值给V_NUM_ARRAY(1),但是因为实际上,该集合变量并没有存储空间,因此PL/SQL就会报一个“下表超出数量”的错误。
如何去解决这个问题呢?查阅Oracle 的MOS 找到了如下描述:
EXTEND Collection Method
EXTENDis a procedure that adds elements to the end of a varray or nested table. The collection can be empty, but not null. (To make a collection empty or add elements to a null collection,
use a constructor. For more information, see "Collection Constructors".)
The
EXTENDmethod has these forms:
EXTENDappends one null element to the collection.
EXTEND(
n
)appends n null
elements to the collection.
EXTEND(
n,
i
)appends n copies
of the ith element to the collection.
Note:
EXTEND(
n,
i
)is
the only form that you can use for a collection whose elements have the
NOT
NULLconstraint.
EXTENDoperates on the internal size of a collection. That is, if
DELETEdeletes an element but keeps a placeholder
for it, then
EXTENDconsiders the element to exist.
Example 5-20 declares a nested table variable, initializing it with three elements; appends two copies of the first
element; deletes the fifth (last) element; and then appends one null element. Because
EXTENDconsiders the deleted fifth element to exist, the appended null element is the sixth element. The procedure
print_ntprints
the nested table variable after initialization and after the
EXTENDand
DELETEoperations. The type
nt_typeand procedure
print_ntare
defined inExample 5-6.
Example 5-20 EXTEND Method with Nested Table
DECLARE nt nt_type := nt_type(11, 22, 33); BEGIN print_nt(nt); nt.EXTEND(2,1); -- Append two copies of first element print_nt(nt); nt.DELETE(5); -- Delete fifth element print_nt(nt); nt.EXTEND; -- Append one null element print_nt(nt); END; /
Result:
nt.(1) = 11 nt.(2) = 22 nt.(3) = 33 --- nt.(1) = 11 nt.(2) = 22 nt.(3) = 33 nt.(4) = 11 nt.(5) = 11 --- nt.(1) = 11 nt.(2) = 22 nt.(3) = 33 nt.(4) = 11 --- nt.(1) = 11 nt.(2) = 22 nt.(3) = 33 nt.(4) = 11 nt.(6) = NULL ---
上面的大意是:
EXTEND方法为VARRAY或者NESTED TABLE集合中的一个或者多个新元素分配存储空间。有两个可以选择的选项,默认情况下,是它在向集合添加值之前的时候,为该值分配存储空间。他的两个参数的意思分别是,第一个参数是增加多少个元素的空间,第二个参数的意思是引用集合中已经存在的元素的索引,该元素就会被复制到新的元素上。
作者 陈字文(热衷于PM\ORACLE\J***A等,欢迎同行交流):ziwen#163.com 扣扣:4零9零2零1零零
上面出错的代码修改为如下可以正常运行了:
DECLARE TYPE NUM_VARRAY IS VARRAY(100) OF NUMBER NOT NULL; V_NUM_VARRAY NUM_VARRAY:=NUM_VARRAY(); BEGIN FOR J IN 1 .. 100 LOOP V_NUM_VARRAY.EXTEND; V_NUM_VARRAY(J) := J; END LOOP; FOR I IN 1 .. V_NUM_VARRAY.COUNT LOOP DBMS_OUTPUT.PUT_LINE(TO_CHAR(V_NUM_VARRAY(I))); END LOOP; END;
相关文章推荐
- PL/SQL developer连接oracle出现“ORA-12154:TNS:could not resolve the connect identifier specified”问题的解决
- PL/SQL developer连接oracle出现“ORA-12154:TNS:could not resolve the connect identifier specified”问题的解决
- PL/SQL developer连接oracle出现“ORA-12154:TNS:could not resolve the connect identifier specified”问题的解决
- 解决PL/SQL登录时出现NLS_LANG没有定义的问题
- PL/SQL中复制中文再粘贴出现乱码问题的解决
- 解决pl/sql登录时只有三个选项和ORA-12154的问题
- PL/SQL中复制中文再粘贴出现乱码问题的解决【转】
- 解决PL/SQL Developer连接数据库时出现 “ORA-12541:TNS:无监听程序”错误
- 解决PL/SQL Developer连接数据库时出现 “ORA-12541:TNS:无监听程序”错误。
- 解决PL/SQL Developer连接数据库时出现 “ORA-12541:TNS:无监听程序”错误。
- PL/SQL出现ORA-03114的解决办法
- Oracle调整内存超出限制出现ORA-27100: shared memory realm already exists问题解决办法
- 出现的问题: A、使用命令行无法登录oracle或者显示ORA-01109:数据库未打开; B、使用PL/SQL登录出现 ORA-01033:ORACLE initialization or
- Oracle调整内存超出限制出现ORA-27100: shared memory realm already exists问题解决办法
- PL/SQL连接不上Oracle报“ORA-12541:TNS:无监听程序”错误疑难问题的解决
- 解决超出打开游标的最大数异常ORA-01000 递归SQL 级别1 出现错误 最全方案-最全方案
- 解决超出打开游标的最大数异常ORA-01000 递归SQL 级别1 出现错误 最全方案-最全方案
- 解决超出打开游标的最大数异常ORA-01000 递归SQL 级别1 出现错误 最全方案-最全方案
- 解决超出打开游标的最大数异常ORA-01000 递归SQL 级别1 出现错误 最全方案-最全方案
- 利用pl/sql developer进行远程连接oracle server出现的问题及解决办法