===============
The first type of collection is known as index-by tables. These behave in the same way as arrays except that have no upper bounds,
allowing them to constantly extend. As the name implies, the collection is indexed using BINARY_INTEGER values, which do not need to be consecutive.
The collection is extended by assigning values to an element using an index value that does not currently exist.
sql>SET SERVEROUTPUT ON SIZE 1000000
sql>DECLARE
TYPE table_type IS TABLE OF NUMBER(10)
INDEX BY BINARY_INTEGER;
v_tab table_type;
v_idx NUMBER;
BEGIN
-- Initialise the collection.
<< load_loop >>
FOR i IN 1 .. 5 LOOP
v_tab(i) := i;
END LOOP load_loop;
-- Delete the third item of the collection.
v_tab.DELETE(3);
-- Traverse sparse collection
v_idx := v_tab.FIRST;
<< display_loop >>
WHILE v_idx IS NOT NULL LOOP
DBMS_OUTPUT.PUT_LINE('The number ' || v_tab(v_idx));
v_idx := v_tab.NEXT(v_idx);
END LOOP display_loop;
END;
/
Ur's
AmarAlam
The first type of collection is known as index-by tables. These behave in the same way as arrays except that have no upper bounds,
allowing them to constantly extend. As the name implies, the collection is indexed using BINARY_INTEGER values, which do not need to be consecutive.
The collection is extended by assigning values to an element using an index value that does not currently exist.
sql>SET SERVEROUTPUT ON SIZE 1000000
sql>DECLARE
TYPE table_type IS TABLE OF NUMBER(10)
INDEX BY BINARY_INTEGER;
v_tab table_type;
v_idx NUMBER;
BEGIN
-- Initialise the collection.
<< load_loop >>
FOR i IN 1 .. 5 LOOP
v_tab(i) := i;
END LOOP load_loop;
-- Delete the third item of the collection.
v_tab.DELETE(3);
-- Traverse sparse collection
v_idx := v_tab.FIRST;
<< display_loop >>
WHILE v_idx IS NOT NULL LOOP
DBMS_OUTPUT.PUT_LINE('The number ' || v_tab(v_idx));
v_idx := v_tab.NEXT(v_idx);
END LOOP display_loop;
END;
/
Ur's
AmarAlam
0 comments:
Post a Comment