-----------------------------------------------------------------
-- PL/SQL: Anonymous block with function (Example 4.4.4)        -
-- Chapter 4; Oracle Programming -- A Primer                    -
--            by R. Sunderraman                                 -
-----------------------------------------------------------------

DECLARE
  enum customers.cno%type;
  total number(10,2);
  status boolean;

  function total_emp_sales(
    emp_no IN  employees.eno%type)
    return number is
  sales number;
  begin
    select sum(price*qty)
    into   sales
    from   orders,odetails,parts
    where  orders.eno = emp_no and
           orders.ono = odetails.ono and
           odetails.pno = parts.pno; 
    return (sales);
  end;

BEGIN
  enum := 1000;
  total := total_emp_sales(enum);
  DBMS_OUTPUT.PUT_LINE('Total sales for employee ' || 
                         enum   || ' is ' || total);
END;
/
