Consider the following table and Do as Directed
SOLUTION .
DECLARE
v_prod_no Product.Prod_No%TYPE;
v_price Product.Price_per_Unit%TYPE;
v_quantity Product.Quantity_Sold%TYPE;
v_total_sale Product.Total_Sale%TYPE;
BEGIN
-- Accept product number from user
v_prod_no := &prod_no;
-- Retrieve price per unit and quantity sold for the given product
SELECT Price_per_Unit, Quantity_Sold
INTO v_price, v_quantity
FROM Product
WHERE Prod_No = v_prod_no;
-- Calculate total sale
v_total_sale := v_price * v_quantity;
-- Update Total_Sale in the table
UPDATE Product
SET Total_Sale = v_total_sale
WHERE Prod_No = v_prod_no;
-- Commit the changes
COMMIT;
-- Display the updated total sale
DBMS_OUTPUT.PUT_LINE('Total sale updated successfully. Total Sale: ' || v_total_sale);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Error: Product not found.');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An unexpected error occurred: ' || SQLERRM);
END;
/