-- order_daily_total.sql

CREATE OR REPLACE FUNCTION order_daily_total
          (in_date DATE DEFAULT SYSDATE)
  RETURN NUMBER
AS
  daily_total NUMBER;
BEGIN
  SELECT sum(price * quantity) INTO daily_total
    FROM product INNER JOIN order_item USING (product_id)
                 INNER JOIN order_header USING (invoice_number)
   WHERE order_date = in_date;
  RETURN daily_total;
END;
/