SQL> set serveroutput on SQL> declare 2 Type customer_table_type is table of emp.empno%type index by binary_integer; 3 custtype customer_table_type; begin ----operator index directly 4 select empno into custtype(-1) from emp where empno = 7369; 5 dbms_output.put_line('custage is: ' || custtype(-1)); ----let query result insert into collection directly 6 select empno bulk collect into custtype from emp; 7 for i in custtype.first..custtype.last loop 8 dbms_output.put_line('the '||i||' position number is ' || custtype(i)); 9 end loop; 10 end; 11 /
custage is: 7369 the 1 position number is 7369 the 2 position number is 7499 the 3 position number is 7521 the 4 position number is 7566 the 5 position number is 7654 the 6 position number is 7698 the 7 position number is 7782 the 8 position number is 7788 the 9 position number is 7839 the 10 position number is 7844 the 11 position number is 7876 the 12 position number is 7900 the 13 position number is 7902 the 14 position number is 7934
SQL> declare
2 Type customer_table_type is table of emp.empno%type index by binary_integer;
3 custtype customer_table_type; begin ----operator index directly
4 select empno into custtype(-1) from emp where empno = 7369;
5 dbms_output.put_line('custage is: ' || custtype(-1)); ----let query result insert into collection directly
6 select empno bulk collect into custtype from emp;
7 for i in custtype.first..custtype.last loop
8 dbms_output.put_line('the '||i||' position number is ' || custtype(i));
9 end loop;
10 end;
11 /
custage is: 7369
the 1 position number is 7369
the 2 position number is 7499
the 3 position number is 7521
the 4 position number is 7566
the 5 position number is 7654
the 6 position number is 7698
the 7 position number is 7782
the 8 position number is 7788
the 9 position number is 7839
the 10 position number is 7844
the 11 position number is 7876
the 12 position number is 7900
the 13 position number is 7902
the 14 position number is 7934
PL/SQL procedure successfully completed
SQL>