create or replace package pack_cursor

  is

    procedure cursor_open;

    procedure cursor_fetch (a number);

    procedure cursor_close;

  end;

  / 


  create or replace package body pack_cursor

  is

    cursor emp_cursor is

      select rownum as no, e.* 

      from (select * from emp

            order by hiredate) e;


    emp_rec emp_cursor%rowtype;


    no number := 1;


    procedure cursor_open

    is

    begin

      if emp_cursor%isopen = false then 

        open emp_cursor;

      end if;

    end;


    procedure cursor_fetch (a number)

    is

    begin

      if emp_cursor%isopen = true then 

        for i in 3..3+4-1 loop

          fetch emp_cursor into emp_rec;

          p(emp_rec.empno||' '||emp_rec.hiredate);

          no := no+1;

        end loop;

      end if;

    end;


    procedure cursor_close

    is

    begin

      close emp_cursor;

    end;


  end;

  / 


  exec pack_cursor.cursor_open

  exec pack_cursor.cursor_fetch(2)


  exec pack_cursor.cursor_fetch(4)

  exec pack_cursor.cursor_fetch(2)


  exec pack_cursor.cursor_close

'Oracle > PL/SQL' 카테고리의 다른 글

15일차 # 4-7  (0) 2012.04.24
15일차 Chapter 4 - Packages II # 4-3  (0) 2012.04.24
15일차 # 3-14: USER_SOURCE data dictionary  (0) 2012.04.24
15일차 # 3-11  (0) 2012.04.24
15일차 # 3-10: PACKAGE BODY  (0) 2012.04.24

+ Recent posts