DECLARE
TYPE number_table IS TABLE OF INTEGER;
number_list NUMBER_TABLE;
-- define local procedure to check and print elements.
PROCEDURE print_list (list_in NUMBER_TABLE)
IS
BEGIN
DBMS_OUTPUT.put_line ('----------------------------------');
FOR i IN list_in.FIRST .. list_in.LAST
LOOP
IF list_in.EXISTS (i)
THEN
DBMS_OUTPUT.put_line ('List [' || list_in (i) || ']');
END IF;
END LOOP;
END print_list;
BEGIN
IF NOT number_list.EXISTS (1) -- Construct collection when one doesn't exist
THEN
number_list := number_table (34,22,3,4,5);
END IF;
DBMS_OUTPUT.put_line ('Nested table before a deletion'); -- print initialized contents
print_list (number_list);
number_list.DELETE (1); -- delete a elements from 2,3, and 4
-- nilai 2 diatas adalah index ke 1 , dimulai dengan index ke 1
DBMS_OUTPUT.put_line (CHR (10) || 'Nested table after a deletion'); -- Print Revised contents
print_list (number_list);
END;
/
output :
/* output
Nested table before a deletion
---------------------------------------
List [34] --> index ke 1
List [22] --> index ke 2
List [3] --> index ke 3
List [4]
List [5]
Nested table after a deletion
---------------------------------------
List [22]
List [3]
List [4]
List [5]
*/
TYPE number_table IS TABLE OF INTEGER;
number_list NUMBER_TABLE;
-- define local procedure to check and print elements.
PROCEDURE print_list (list_in NUMBER_TABLE)
IS
BEGIN
DBMS_OUTPUT.put_line ('----------------------------------');
FOR i IN list_in.FIRST .. list_in.LAST
LOOP
IF list_in.EXISTS (i)
THEN
DBMS_OUTPUT.put_line ('List [' || list_in (i) || ']');
END IF;
END LOOP;
END print_list;
BEGIN
IF NOT number_list.EXISTS (1) -- Construct collection when one doesn't exist
THEN
number_list := number_table (34,22,3,4,5);
END IF;
DBMS_OUTPUT.put_line ('Nested table before a deletion'); -- print initialized contents
print_list (number_list);
number_list.DELETE (1); -- delete a elements from 2,3, and 4
-- nilai 2 diatas adalah index ke 1 , dimulai dengan index ke 1
DBMS_OUTPUT.put_line (CHR (10) || 'Nested table after a deletion'); -- Print Revised contents
print_list (number_list);
END;
/
output :
/* output
Nested table before a deletion
---------------------------------------
List [34] --> index ke 1
List [22] --> index ke 2
List [3] --> index ke 3
List [4]
List [5]
Nested table after a deletion
---------------------------------------
List [22]
List [3]
List [4]
List [5]
*/
No comments:
Post a Comment