oracle sql中查询ip段内的记录

sql 语句中使用如下(ip值的存储类型为varchar):

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;

}

猜你喜欢

转载自blog.csdn.net/lanfeng330/article/details/9215005