Q
Problem solve Get help with specific problems with your technologies, process and projects.

Sorting substrings of different lengths numerically, part 2

Here is the rest of Rudy's answer. See part one.

Anyhow, this detailed explanation could go on for a lot longer, so I'll just jump ahead to the end and give you the full query --

 SELECT IPno , RIGHT('00'& MID(IPno ,1 ,INSTR(IPno,'.')-1) , 3 ) , RIGHT('00'& MID(IPno ,INSTR(IPno,'.')+1 ,INSTR(MID(IPno ,INSTR(IPno,'.')+1) ,'.')-1) , 3 ) , RIGHT('00'& MID(IPno ,INSTR(MID(IPno ,INSTR(IPno,'.')+1) ,'.') +INSTR(IPno,'.')+1 ,INSTR(MID(IPno ,INSTR(MID(IPno ,INSTR(IPno,'.')+1) ,'.') +INSTR(IPno,'.')+1) ,'.')-1) , 3 ) , RIGHT('00'& MID(IPno ,INSTR(MID(IPno ,INSTR(MID(IPno ,INSTR(IPno,'.')+1) ,'.') +INSTR(IPno,'.')+1) ,'.') +INSTR(MID(IPno ,INSTR(IPno,'.')+1) ,'.') +INSTR(IPno,'.')+1) , 3 ) FROM IPtable ORDER BY 2, 3, 4, 5;

Ugly, isn't it? What a great candidate for a view!

 CREATE VIEW IPnumbers (IPno, IP1, IP2, IP3, IP4) AS  the SELECT statement above, minus the ORDER BY clause

Then you could say

 SELECT IPno, IP1, IP2, IP3, IP4 FROM IPnumbers ORDER BY IP1, IP2, IP3, IP4


This was last published in June 2002

Dig Deeper on Oracle and SQL

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close