PL/SQL Nested Table

PL/SQL Nested Table – How to write syntax, example

The plsql Nested Table are indexed arrays whose size is not fixed and INDEX BY BINARY_INTEGER clause is missing.

The Nested Table syntax is:

TYPE type_name IS TABLE OF { { element_type | variable%TYPE |
table.column%TYPE }[NOT NULL]} | table%ROWTYPE };
var_nested type_name;

Nested Table example:

DECLARE
	TYPE table_no IS TABLE OF NUMBER;
	TYPE table_index IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
	v_tno table_no := table_no(-3, 34.5, 7.15268, NULL, 0);
	v_Count BINARY_INTEGER := 1;
	v_ti table_index;
BEGIN
DBMS_OUTPUT.PUT_LINE('Start Nested Table');
LOOP
	IF v_tno.EXISTS(v_Count) THEN
		DBMS_OUTPUT.PUT_LINE('v_tno(' || v_Count || '): ' ||v_tno(v_Count));
		v_ti(v_count) := v_tno(v_count);
		v_Count := v_Count + 1;
	ELSE
		EXIT;
	END IF;
END LOOP;
v_Count := v_ti.COUNT;
DBMS_OUTPUT.PUT_LINE('Start Indexed Arrays');
LOOP
	IF v_ti.EXISTS(v_Count) THEN
		DBMS_OUTPUT.PUT_LINE('v_ti(' || v_Count || '): ' ||v_ti(v_Count));
		v_Count := v_Count - 1;
	ELSE
		EXIT;
	END IF;
END LOOP;
END;