sql 语句中使用如下:
TO_NUMBER(REGEXP_SUBSTR(login_ip,'\\w+',1,1))*POWER(2,24)+
TO_NUMBER(REGEXP_SUBSTR(login_ip,'\\w+',1,2))*POWER(2,16)+
TO_NUMBER(REGEXP_SUBSTR(login_ip,'\\w+',1,3))*POWER(2,8)+
TO_NUMBER(REGEXP_SUBSTR(login_ip,'\\w+',1,4))*POWER(2,0)>=?
程序中传入参数进行转换(原始ip参数为字符串):
public static long convert(String ip) {
String[] ips = ip.split("\\.");
long result = 0;
for (int i = 0; i < 4; i++) {
long temp = Integer.parseInt(ips[i]);
result += temp << ((3 - i) * 8);
}
return result;
}

本文介绍了一种将IP地址从字符串格式转换为数值格式的方法,包括SQL查询和Java程序实现。通过位移运算和数学计算,可以高效地完成IP地址的数值化,便于在网络设备管理和数据库操作中使用。
9819

被折叠的 条评论
为什么被折叠?



