It sounds like you just want a SUM
SELECT SUM(prod_sale_price*prod_quantity)
INTO total_order_cost
FROM order_details od
JOIN products p
ON od.prod_id = p.prod_id
WHERE order_id = given_id;
There doesn't appear to be any need to do the COUNT
or to introduce a loop.