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;
}