问题描述
我一直在不同的 oracle.com 站点上阅读,
FOR i IN nested_table.FirsT .. nested_table.LAST
是您通常在 PLsql 中执行的操作,当迭代嵌套表类型的所有元素时(只要没有删除元素)。
我的嵌套表存在的方式是通过做
type nested_table_type is table of varchar2(20)
在不同的包中
nested_table other_package.nested_table_type := other_package.nested_table_type();
然后,在一个循环中
nested_table.extend;
nested_table(nested_table.last) := something;
任意次数。 然后,我想对每个值做一些事情,有点像在其他语言中使用 for each 。我可以在这里使用 for 循环吗?有人告诉我要小心,因为 Oracle 中的索引可能没有顺序,所以 for 循环可能不会考虑某些索引。我绝对应该使用这个,他说:
index := nested_table.first;
while (index is not null)
loop
do things...
index := nested_table.next(index);
end loop;
这是真的吗?索引如何不按顺序排列或 for 循环不遍历所有索引?
感谢您的帮助:)
编辑:
这很可能是某种误传。我留下了代码。尽管如此,感谢您的阅读/回答,希望这对将来的某人或某事有所帮助:)
解决方法
索引是有序的,只是你可以创建稀疏表,这意味着可能会丢失一些索引。
但是,对于您的情况,使用 i IN t.FIRST .. t.LAST
完全没问题。