• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 536
  • Last Modified:

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
0
Blowfelt82
Asked:
Blowfelt82
1 Solution
 
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
 
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
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.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now