Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Oracle
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;
Posted 13-Feb-13 19:33pm
7prince409
Edited 13-Feb-13 19:34pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 275
1 OriginalGriff 230
2 BillWoodruff 173
3 CPallini 155
4 Kamal Rocks 144
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100