/* Function to receive an order_id value as an input parameter, and return the sales tax value, based on the customer's state of residence */ FUNCTION calc_tax (current_order_id NUMBER) RETURN NUMBER IS customer_state CHAR(2); total_order_amount NUMBER; tax_amount NUMBER; BEGIN --determine customer state of residence SELECT state INTO customer_state FROM customer, cust_order WHERE customer.cust_id = cust_order.cust_id AND order_id = current_order_id; --determine total order amount SELECT SUM(price * order_quantity) INTO total_order_amount FROM cust_order, order_line, inventory WHERE cust_order.order_id = order_line.order_id AND order_line.inv_id = inventory.inv_id AND cust_order.order_id = current_order_id; --determine sales tax amount based on residence --charge WI residents 6% tax, all other residents 0% tax IF customer_state = 'WI' THEN tax_amount := .06 * total_order_amount; ELSE tax_amount := 0; END IF; --return function value RETURN tax_amount; END;