Solved

Order version numbers in Oracle.

Posted on 2013-05-13
6
519 Views
Last Modified: 2013-05-14
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
Comment
Question by:Blowfelt82
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 39163753
just do a conversion to a number and all should be fine

order by to_number(your_column)
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 39163754
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
 
LVL 23

Accepted Solution

by:
OP_Zaharin earned 500 total points
ID: 39163758
- 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Closing Comment

by:Blowfelt82
ID: 39163768
Worked like a charm - thanks
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 39163770
glad able to help :)
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39163884
:)

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

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Viewers will learn how the fundamental information of how to create a table.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question