Topic: SQL*Plus and PL/SQL >> How to sort data in varchar field?
|
Disclaimer: The purpose of all dbapool forums including OCP and Other Oracle Certification forums is to help each other with specific issues but not to share dump and copyrighted exam content, materials or intellectual property.
You may review the entire Oracle Certification Program Candidate Agreement online Here.
|
|
|
|
| Title: How to sort data in varchar field? |
| Irfan |
Posted: Apr 03, 2008 07:19:30 AM |
Total Post: 29
Joined: Nov, 2005
|
Hi All,
I am having data in table as below.
range POINTS
0-0 96755
1-10 54519
10-30 33101
100-250 15297
250-400 5200
30-50 16083
400+ 9499
50-100 19214
But I want it to be displayed as
range POINTS
0-0 96755
1-10 54519
10-30 33101
30-50 16083
50-100 19214
100-250 15297
250-400 5200
400+ 9499
Since range column is varchar order by is not working .
Pls help... |
|
|
Murtuja |
| Posted: Apr 03, 2008 08:54:33 AM | |
|
Total Post: 857
Joined: Jan, 2006
|
Hi,
create table srttest (col1 varchar2(10),col2 varchar2(10))
insert into srttest values ('0-0' ,'96755');
insert into srttest values ('1-10' ,'54519');
insert into srttest values ('50-100' ,'19214');
insert into srttest values ('100-250' ,'15297');
insert into srttest values ('250-400' ,'5200');
insert into srttest values ('400+' ,'9499');
insert into srttest values ('10-30' ,'33101');
insert into srttest values ('30-50' ,'16083');
select * from srttest
order by to_number(substr(col1,1,instr(col1,'-')-1))
|
|
|
|
|
Irfan |
| Posted: Apr 03, 2008 09:09:54 AM | |
|
Total Post: 29
Joined: Nov, 2005
|
|
|
|
|
Murtuja |
| Posted: Apr 03, 2008 01:00:48 PM | |
|
Total Post: 857
Joined: Jan, 2006
|
All,
If all members can provide "create table" and "Insert statements" in their sql related questions then it would be easy to test.
|
|
|
|
|
| Time Zone: EDT |
Send this thread to your friend |
|
|
|
|
Forum Rules & Description
Who Can Read The Forum? Any registered user or guest
Who Can Post New Topics? Any registered user
Who Can Post Replies? Any registered user
|
| |
Get FREE Magazines
|
Top 10 Forum User
|
| Murtuja Khokhar | 857 |
| Mohammed Taj | 746 |
| positive fanatic | 483 |
| Jayanta Sur | 479 |
| Vigyan Kaushik | 386 |
| Gopu Gopi | 327 |
| Gitesh Trivedi | 322 |
| Vinoth Kumar | 264 |
| neeraj sharma | 258 |
| Ramesh Jois | 246 |
|
|