Home » SQL & PL/SQL » SQL & PL/SQL » Help needed
Help needed [message #6892] Sat, 10 May 2003 04:13 Go to next message
shawlin
Messages: 25
Registered: April 2003
Junior Member
Hello

I want a pl.sql block
i will accept from the user a series say '10,25,3,19'
Find the least number in the series and place it
in the beginning and second least like wise.
The final result should be something like this.
3,10,19,25.
Even i am trying the way.somehow i got struck
often.kindly help me get this series.

Thanks and regards
shawlin
Re: Help needed [message #6895 is a reply to message #6892] Sat, 10 May 2003 05:23 Go to previous messageGo to next message
Cindreen Clarence
Messages: 41
Registered: March 2003
Location: Bangalore
Member
Hi Shawlin,

Hope this works.

SQL> desc numbers
Name Null? Type
---------- -------- ------
NO NUMBER

SQL> create or replace procedure c_sort
2 is
3 type num is table of number index by binary_integer;
4 nums num;
5 cursor c1 is select no from numbers;
6 x number := 1;
7 total number;
8 copy number;
9 begin
10 for c in c1 loop
11 nums(x) := c.no;
12 x := x +1;
13 end loop;
14 total := nums.count;
15 for i in 1..total-1 loop
16 for j in i+1..total loop
17 if nums(i) > nums(j) then
18 copy := nums(i);
19 nums(i) := nums(j);
20 nums(j) := copy;
21 end if;
22 end loop;
23 end loop;
24 for x in 1..total loop
25 dbms_output.put_line(nums(x));
26 end loop;
27 end;
28 /

Procedure created.

SQL> select * from numbers;

NO
----------
29
1
45
78
33
22
7
10
6
49
35

11 rows selected.

SQL> execute c_sort
1
6
7
10
22
29
33
35
45
49
78

PL/SQL procedure successfully completed.

Best Regards
Ciona
Re: Help needed [message #6902 is a reply to message #6895] Sat, 10 May 2003 10:06 Go to previous message
shawlin
Messages: 25
Registered: April 2003
Junior Member
well.thanks.that's nice.

but i want to do in the simple pl.sql block.
I will get the user input like '10,21,6,11,19,3'
then i will rearrange the same as 3,6,10,11,19,21
something like this.I will part this series
in return.I really thank you for your approach.
But if u could try only with pl.sql
block not going for a procedure.Is it really
possible to do what i really want.

Hope u can understand what i am asking.

thanks for the help.

shawlin
Previous Topic: SQL HELP
Next Topic: check date is later than current date.
Goto Forum:
  


Current Time: Thu Apr 18 19:49:07 CDT 2024