Currently, the query output is; There are 2 items with the highest price: $80.00
How can I show the partids for the highest price in the program below as well.?
I would like the output to be: There are 2 items with the highest price: $80.00 with partids(This should be the partids of the highest prices).
DECLARE
vPrice inventory.price%TYPE;
vPartid inventory.partid%TYPE;
vcnt INTEGER;
CURSOR highestprice_cur
IS
SELECT price, vcnt,vpartid
--INTO vprice, vcnt
FROM (SELECT price, COUNT(*) vcnt
FROM inventory
GROUP BY price
ORDER BY price DESC)
WHERE ROWNUM =1;
highestprice_items_cur highestprice_cur%ROWTYPE;
BEGIN
OPEN highestprice_cur;
LOOP
FETCH highestprice_cur INTO vprice, vcnt,vpartid;
EXIT
WHEN highestprice_cur%NOTFOUND;
IF vcnt > 1
THEN
DBMS_OUTPUT.put_line(
'There are '
|| vcnt || ' items with the highest price: '
|| TO_CHAR(vprice, 'fm$999,99.00'));
END IF;
END LOOP;
CLOSE highestprice_cur;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line('ERROR OTHERS ' || SQLERRM);
END;