Oracle PL/SQL - Defining cursors in the package body


Defining cursors in the package body

drop table emp;
create table emp(
  empno    number(4,0),
  ename    varchar2(10),
  job      varchar2(9),
  mgr      number(4,0),
  hiredate date,
  sal      number(7,2),
  comm     number(7,2),
  deptno   number(2,0)

insert into emp values(7839, 'KING', 'PRESIDENT', null, to_date('17-11-1981','dd-mm-yyyy'), 5000, null, 10);
insert into emp values(7698, 'BLAKE', 'MANAGER', 7839,to_date('1-5-1981','dd-mm-yyyy'), 2850, null, 30);
insert into emp values(7782, 'CLARK', 'MANAGER', 7839,to_date('9-6-1981','dd-mm-yyyy'), 2450, null, 10);
insert into emp values(7566, 'JONES', 'MANAGER', 7839,to_date('2-4-1981','dd-mm-yyyy'), 2975, null, 20);
insert into emp values(7788, 'SCOTT', 'ANALYST', 7566,to_date('13-JUL-87','dd-mm-rr') - 85, 3000, null, 20);

create or replace package body bigUtil is
      cursor c_emp is                                                   
        select *
           from emp;
      r_emp c_emp%ROWTYPE;

     procedure p_printEmps is
           r_emp c_emp%ROWTYPE;
           open c_emp;                                                  
                fetch c_emp into r_emp;
                exit when c_emp%NOTFOUND;
           end loop;
           close c_emp;
      end; --p_printEmps

end; --bigUtil

Related Topic