-----------------------------------------------------------------
-- PL/SQL: Cursor-based record (Section 4.7.2)                  -
-- Chapter 4; Oracle Programming -- A Primer                    -
--            by R. Sunderraman                                 -
-----------------------------------------------------------------

DECLARE
  cursor c1 is
    select orders.eno employee_no,
           ename employee_name,
           sum(price*qty) total_sales
    from   employees,orders,odetails,parts
    where  employees.eno = orders.eno and
           orders.ono = odetails.ono and
           odetails.pno = parts.pno
    group by orders.eno, ename;

  emp_sales_rec c1%rowtype;

BEGIN
  open c1;
  loop
    fetch c1 into emp_sales_rec;
    exit when c1%NOTFOUND;
    dbms_output.put_line(emp_sales_rec.employee_no ||
                         '  ' ||
                         emp_sales_rec.employee_name ||
                         '  ' ||
                         emp_sales_rec.total_sales);
  end loop;
  close c1;
END;
/
