oracle pl/sql 循环比较集合元素是否相同

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
请使用浏览器的分享功能分享到微信等