본문 바로가기

Database/PLSQL

022 - [Oracle PL/SQL] Cursor - Explicit Cursor Attributes

<샘플코드에서 사용한 데이터는 HR 스키마이고, 오라클 설치시 생성할 수 있는 기본 스키마 입니다>

 

 

 

 

 

 

 

# using c_emp%notfound, c_emp%isopen,c_emp%rowcount

DECLARE
  CURSOR c_emp is
  SELECT employee_id,first_name FROM employees order by employee_id;
  v_empno employees.employee_id%type;
  v_first_name employees.first_name%type;

BEGIN
 if c_emp%isopen then
 null;
 else
 open c_emp;
 end if;
    dbms_output.put_line('the counter for cursor now is '||c_emp%rowcount);
  loop
      fetch c_emp into v_empno, v_first_name;
      exit when c_emp%notfound or  c_emp%rowcount>10 ;
      dbms_output.put_line(c_emp%rowcount||' '||v_empno||' '||v_first_name);
  end loop;
    dbms_output.put_line('the counter for cursor now is '||c_emp%rowcount);
  close c_emp;
END;
---------------------------
the counter for cursor now is 0
1 100 Steven
2 101 Neena
3 102 Lex
4 103 Alexander
5 104 Bruce
6 105 David
7 106 Valli
8 107 Diana
9 108 Nancy
10 109 Daniel
the counter for cursor now is 11