关于IP的SQL排序方法:(Oracle版本)
如果有一个表如下所示:
create table iptable (ip varchar(20))
select ip,to_number(substr(ip,1,instr(ip,'.',1,1)-1)) as newip1,to_number(substr(ip,instr(ip,'.',1,1)+1,instr(ip,'.',1,2)-instr(ip,'.',1,1)-1)) as newip2,to_number(substr(ip,instr(ip,'.',1,2)+1,instr(ip,'.',1,3)-instr(ip,'.',1,2)-1)) as newip3,to_number(substr(ip,instr(ip,'.',1,3)+1,length(ip)+1-instr(ip,'.',1,3))) as newip4 from iptable order by newip1,newip2,newip3,newip4