These are one dimensional arrays and are indexed by integers.
Example:
Type my_first_table is table of varchar2(10)Index by binary_integer;
Var_of_table my_first_table;
Var_of_table(1) := ‘hello world’;
Var_of_table(2) := ‘bye’;
Example:
Type my_emp_table is table of emp%rowtype
Index by binary_integer:
Var_of_emp my_emp_table;
Var1_of_emp my_emp_table;
Var_of_emp(1).ename := ‘sachin’;
Var_of_emp(1).empno := 20;
Var_of_emp(1).sal := 3000;
To delete individual records:
Var_of_emp .delete(1);
To remove all entries from a table:
Var_of_emp.delete;
Or
Var_of_emp := var1_of_emp
Where var1_of_emp does not contain any value, it is empty.
COUNT method can be used to return number of records in a PL/SQL Table.
Var_of_table.count
First, Next and Last methods of PL/SQL Tables.
First is for first index in the PL/SQL Tables.
Last is for last index in the PL/SQL Tables.
Next is for next index in the PL/SQL Tables.
Example:
SQL> set serveroutput on
SQL> Declare
2
3 Type my_dept_table is table of varchar2(20)
4 Index by binary_integer;
5
6 Var_of_dept my_dept_table;
7 Index_value number;
8
9 Begin
10
11 For dept_rec in (select * from dept) loop
12 Var_of_dept(dept_rec.deptno) := dept_rec.dname;
13 End loop;
14
15 Index_value := var_of_dept.first;
16 Loop
17 Exit when index_value is null;
18 Dbms_output.put_line (index_value || ' ' ||var_of_dept(index_value));
19 Index_value := var_of_dept.next(index_value);
20 End loop;
21 End;
22 /
10 ACCOUNTING
20 RESEARCH
30 SALES
40 OPERATIONS
PL/SQL procedure successfully completed.