Home » SQL & PL/SQL » SQL & PL/SQL » Find maximum number by using while loop ??
icon4.gif  Find maximum number by using while loop ?? [message #398798] Fri, 17 April 2009 11:49 Go to next message
logic
Messages: 2
Registered: April 2009
Junior Member
hello,

I am new to pl sql , can you help me with this .

I have a table of ONE column only consist of numbers,

how can I find the maximum number by using while loop only ?

Thank you very much
Re: Find maximum number by using while loop ?? [message #398803 is a reply to message #398798] Fri, 17 April 2009 12:01 Go to previous messageGo to next message
Michel Cadot
Messages: 68737
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Post what you already tried, we don't do homework for you but we can help you to correct what you do.

Regards
Michel
Re: Find maximum number by using while loop ?? [message #398857 is a reply to message #398798] Sat, 18 April 2009 10:54 Go to previous messageGo to next message
logic
Messages: 2
Registered: April 2009
Junior Member
I have a table named number_table with one column called NUM consist of the numbers from 1 to 10, the result should be 10 .


Declare
Cursor c is select * from number_table;
test c%ROWTYPE;
max number :=1;
Begin
open c;
fetch c into test;
WHILE test.NUM > max LOOP
max = test.NUM
DBMS_OUTPUT.PUT_LINE(max);
END LOOP;
End;
Re: Find maximum number by using while loop ?? [message #398858 is a reply to message #398798] Sat, 18 April 2009 11:32 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
You need to help us by following the Posting Guidelines as stated below.
http://www.orafaq.com/forum/t/88153/0/
Please, please, please Read & Follow Posting Guidelines above.
Go to the section labeled "Practice" & do as directed.


Rows in a table have no inherent order.
What happens if/when the "first" row return 3 & next row is 2?

[Updated on: Sat, 18 April 2009 12:13]

Report message to a moderator

Re: Find maximum number by using while loop ?? [message #398863 is a reply to message #398857] Sat, 18 April 2009 13:28 Go to previous message
Michel Cadot
Messages: 68737
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
First write the algorithm you want to use in english (or your native language) then translate this algorithm in PL/SQL.

Regards
Michel
Previous Topic: fetching evenly distributed records throughout the day
Next Topic: Entering php variables into SP
Goto Forum:
  


Current Time: Fri Feb 14 09:59:16 CST 2025