程序如下
DECLARE
TYPE NumList IS TABLE OF NUMBER;
n NumList := NumList(1,3,5,7);
counter INTEGER;
BEGIN
DBMS_OUTPUT.PUT_LINE('N''s first subscript is ' || n.FIRST);
DBMS_OUTPUT.PUT_LINE('N''s last subscript is ' || n.LAST);
-- When the subscripts are consecutive starting at 1,
-- it's simple to loop through them.
FOR i IN n.FIRST .. n.LAST
LOOP
DBMS_OUTPUT.PUT_LINE('Element #' || i || ' = ' || n(i));
END LOOP;
n.DELETE(2); -- Delete second element.
-- When the subscripts have gaps or the collection might be uninitialized,
-- the loop logic is more extensive(广阔). We start at the first element, and
-- keep looking for the next element until there are no more.
IF n IS NOT NULL THEN
counter := n.FIRST;
WHILE counter IS NOT NULL
LOOP
DBMS_OUTPUT.PUT_LINE('Element #' || counter || ' = ' || n(counter));
counter := n.NEXT(counter);
END LOOP;
ELSE
DBMS_OUTPUT.PUT_LINE('N is null, nothing to do.');
END IF;
END;
/-------------------打印结果如下
N's first subscript is 1
N's last subscript is 4
Element #1 = 1
Element #2 = 3
Element #3 = 5
Element #4 = 7
Element #1 = 1
Element #3 = 5
Element #4 = 7文档说:When the subscripts have gaps or the collection might be uninitialized,
-- the loop logic is more extensive(广阔). We start at the first element, and
-- keep looking for the next element until there are no more.
我的理解是 嵌套表可以任意删除元素, 但是全部检索数据时,会从第一个元素到最后一个分配的空间,
文档说
keep looking for the next element until there are no more.
寻找下个元素知道没有为止,这里指的是没有分配的空间吧!,要不然一个从1..100的嵌套表 我删除2..99位置的元素.只有前后两个元素.他的检索过程是怎么样的
DECLARE
TYPE NumList IS TABLE OF NUMBER;
n NumList := NumList(1,3,5,7);
counter INTEGER;
BEGIN
DBMS_OUTPUT.PUT_LINE('N''s first subscript is ' || n.FIRST);
DBMS_OUTPUT.PUT_LINE('N''s last subscript is ' || n.LAST);
-- When the subscripts are consecutive starting at 1,
-- it's simple to loop through them.
FOR i IN n.FIRST .. n.LAST
LOOP
DBMS_OUTPUT.PUT_LINE('Element #' || i || ' = ' || n(i));
END LOOP;
n.DELETE(2); -- Delete second element.
-- When the subscripts have gaps or the collection might be uninitialized,
-- the loop logic is more extensive(广阔). We start at the first element, and
-- keep looking for the next element until there are no more.
IF n IS NOT NULL THEN
counter := n.FIRST;
WHILE counter IS NOT NULL
LOOP
DBMS_OUTPUT.PUT_LINE('Element #' || counter || ' = ' || n(counter));
counter := n.NEXT(counter);
END LOOP;
ELSE
DBMS_OUTPUT.PUT_LINE('N is null, nothing to do.');
END IF;
END;
/-------------------打印结果如下
N's first subscript is 1
N's last subscript is 4
Element #1 = 1
Element #2 = 3
Element #3 = 5
Element #4 = 7
Element #1 = 1
Element #3 = 5
Element #4 = 7文档说:When the subscripts have gaps or the collection might be uninitialized,
-- the loop logic is more extensive(广阔). We start at the first element, and
-- keep looking for the next element until there are no more.
我的理解是 嵌套表可以任意删除元素, 但是全部检索数据时,会从第一个元素到最后一个分配的空间,
文档说
keep looking for the next element until there are no more.
寻找下个元素知道没有为止,这里指的是没有分配的空间吧!,要不然一个从1..100的嵌套表 我删除2..99位置的元素.只有前后两个元素.他的检索过程是怎么样的
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货