FUNCTION cust_sales (p_cust_id NUMBER, p_from DATE, p_to DATE)                 /* PL/SQL */
    RETURN NUMBER
IS
    v_sum NUMBER;
BEGIN
    EXECUTE IMMEDIATE
        'SELECT SUM(amount_sold) FROM sh.promo_sales ' ||
        'WHERE customer_id = :customer_id '            ||
        'AND date BETWEEN :date_from AND :date_to'
    INTO 
        v_sum
    USING 
        p_cust_id, 
        p_from, p_to;

    RETURN (v_sum);
END;

