Using Table Type:
Tabletype is a set of datatype which stores the table values and it can be accessed. It consists of several collection methods.
Syntax:
Type <typename> is Table of <datatype> index by binary_integer;
Here typename denotes the name of the type and the datatype is the type it can contain and index by binary_integer specifies which it can contain a dynamic range of values.
Example
DECLARE
TYPE VTAB IS TABLE OF VARCHAR2(10) INDEX BY BINARY_INTEGER;
TAB VTAB;
J BINARY_INTEGER:=0;
CURSOR C1 IS SELECT ENAME FROM EMP;
BEGIN
FOR I IN C1 LOOP
J:=J+1;
TAB(J):=I.ENAME;
DBMS_OUTPUT.PUT_LINE(TAB(J));
END LOOP;
END;
In the above example, vtab is declared as a table type. Because it can contain any number of data the index must be specified. This displays all the records. In sequence to display specific values or collection methods are used.