SQL> select empno,ename,deptno from emp;
EMPNO ENAME DEPTNO
----- ---------- ------
7369 SMITH 20
7499 ALLEN 30
7521 WARD 30
7566 JONES 20
7654 MARTIN 30
7698 BLAKE 30
7782 CLARK 10
7788 SCOTT 20
7839 KING 10
7844 TURNER 30
7876 ADAMS 20
7900 JAMES 30
7902 FORD 20
7934 MILLER 10
14 rows selected
SQL>
SQL> declare
2 type t_deptno is table of emp.deptno%type index by binary_integer;
3 cursor cur_emp is select deptno from emp order by deptno;
4 v_deptno t_deptno;
5 v_1 emp.deptno%type;
6 begin
7 open cur_emp;
8 fetch cur_emp bulk collect into v_deptno;
9 dbms_output.put_line(v_deptno(1));
10 for i in 1..v_deptno.count loop
11 if v_1!=v_deptno(i) then
12 dbms_output.put_line(v_deptno(i));
13 end if;
14 v_1:=v_deptno(i);
15 end loop;
16 close cur_emp;
17 end;
18 /
10
20
30
PL/SQL procedure successfully completed
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-713314/,如需转载,请注明出处,否则将追究法律责任。