Job Seekers   Employers
dbapool: Authors | Submissions | Contact Us
   Forgot password? | Sign up
  Home   Discussion Forum   Articles   Interview Questions   FAQs   Scripts   Rewards   Analyzer   White Papers   Blog   Certification   Downloads   Tools
 

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






 
Hi,
Thanks its working..

 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

  




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 Khokhar857
  Mohammed Taj746
  positive fanatic483
  Jayanta Sur479
  Vigyan Kaushik386
  Gopu Gopi327
  Gitesh Trivedi322
  Vinoth Kumar264
  neeraj sharma258
  Ramesh Jois246






oracle Mag



  About Us Advertise Terms of Use Privacy Newsletters Contact Us    

Home   Discussion Forum   FAQs  Articles  Jobs   Newsletters  Directory  Downloads 

Our Premium Sponsor
Confio Software