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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
OP_ZaharinConnect With a Mentor Commented:
- 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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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

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
All Courses

From novice to tech pro — start learning today.