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.4HardCODE

Stored Procedure - Retrieving Top 10 Products Based on Highest Unit Price

Question

Solution

SQL

CREATE OR REPLACE PROCEDURE get_top_products()
LANGUAGE plpgsql
AS $$
DECLARE
	v_product_name VARCHAR(100);
	v_unit_price NUMERIC;
BEGIN
	FOR v_product_name, v_unit_price IN
		SELECT product_name, unit_price
		FROM products
		ORDER BY unit_price DESC
		LIMIT 10
	LOOP
		RAISE NOTICE 'Product: %, Price: %', v_product_name, v_unit_price;
	END LOOP;
END;
$$;

1/1 test cases passed

No hidden test cases