Order version numbers in Oracle.

In Oracle SQL how can I sort by version numbers, at the moment version numbers are as follows when I do a simple order by of the version column...

6.0.1
6.0.10
6.0.11
6.0.12
6.0.13
6.0.14
6.0.2
6.0.3

The list should be as follows...

6.0.1
6.0.2
6.0.3
6.0.10
6.0.11
6.0.12
6.0.13
6.0.14
Blowfelt82Asked:
Who is Participating?
 
OP_ZaharinCommented:
- try using lpad() function if your column is not number datatype

- my example below pads the front of the data with spaces up to 10 characters as your data length is 6. you can increase the 10 if the data length in the version column is more than 10.

SELECT version FROM tablename
ORDER BY LPAD(version, 10);
0
 
Naveen KumarProduction Manager / Application Support ManagerCommented:
just do a conversion to a number and all should be fine

order by to_number(your_column)
0
 
Naveen KumarProduction Manager / Application Support ManagerCommented:
you need to ensure that no characters etc are there in that version number column otherwise you will get an error saying invalid number when you use to_number(..) conversion.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Blowfelt82Author Commented:
Worked like a charm - thanks
0
 
OP_ZaharinCommented:
glad able to help :)
0
 
PortletPaulfreelancerCommented:
:)

interesting question, I was thinking of regexp_ replace for this, but I hate regular expressions to be honest so I went looking and:
a different approach is recorded here
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.