This website is for reference purposes only. Users are responsible for any misuse. The owner is not liable for any consequences.
Back to Database Management Systems (Laboratory)
6.1.3HardCODE

Stored Procedures - Calculating Total Ordered Quantity for a Given Product

Question

Solution

SQL

CREATE OR REPLACE PROCEDURE get_total_quantity(
	IN p_product_name VARCHAR,
	OUT p_total_quantity INT
)

LANGUAGE plpgsql
AS $$
BEGIN
	SELECT COALESCE(SUM(quantity), 0)
	INTO p_total_quantity
	FROM product_orders
	WHERE product_name = p_product_name;TRIM(LOWER(product_name)) = TRIP (LOWER(p_product_name));

	RAISE NOTICE 'Total Quantity for %: %', p_product_name, p_total_quantity;
END;
$$;

2/2 test cases passed

No hidden test cases