I've had this around for a while ... and just dug it out of my scripts and tried it again . Works for sorting 4 octet ips. You can always add sections on if they are ipv6.
Ugly looking ... but it works. Note, you can probably clean up the math a bit ... i.e. combine plusses into +2, +3 etc. I just never did because it worked. select ip from iptable order by lpad(substr(ip,1,instr(ip,'.')-1),3,'0')|| lpad(substr(ip, instr(ip,'.')+1,(instr(ip,'.',instr(ip,'.')+1)-1)-instr(ip,'.')),3,'0')|| lpad(substr(ip, instr(ip,'.',instr(ip,'.')+1)+1,(instr(ip,'.',instr(ip,'.',instr(ip,'.')+1)+ 1))-instr(ip,'.',instr(ip,'.')+1)-1),3,'0')|| lpad(substr(ip, instr(ip,'.',instr(ip,'.',instr(ip,'.')+1)+1)+1),3,'0') -----Original Message----- Sent: Tuesday, March 25, 2003 11:54 AM To: Multiple recipients of list ORACLE-L Need a trick to sort ip addresses into numerical order. I have them stored as varchar2. If I select without a sort I get rows in order of their character value: 10.0.112.1 10.0.113.1 10.0.113.2 10.0.12.1 10.0.78.1 I'd like to order them numerically within the octets: 10.0.12.1 10.0.78.1 10.0.112.1 10.0.113.1 10.0.113.2 =============================================================== Ray Stell [EMAIL PROTECTED] (540) 231-4109 KE4TJC 28^D -- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Ray Stell INET: [EMAIL PROTECTED] Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). -- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Kevin Lange INET: [EMAIL PROTECTED] Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).
