Ip地址排序(Oracle下)

1.多网段情况下:

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 itemfound 
order by newip1,newip2,newip3,newip4 

 

2. 单个网段情况下:

select ip,  

 
to_number(substr(ip,instr(ip,'.',1,3)+1,length(ip)+1-instr(ip,'.',1,3))) as newip4   
from itemfound 
order by newip4 

 

 

你可能感兴趣的:(oracle)