您可以存储一个IP为一个数字,这是他们内部是如何存在的,但你必须编写代码来来回转换:
#include <arpa/inet.h>
/*
* Returns a pointer to an internal array containing the string, which is overwritten with each call to the function.
* You need to copy the string if you want to keep the value returned.
*/
extern char *inet_ntoa (struct in_addr in);
/*
* Convert Internet host address from numbers-and-dots notation in CP
* into binary data and store the result in the structure inp.
*/
extern int inet_aton (const char *cp, struct in_addr *inp);
下面是一些简单的SQL,做的什么人这些做ip-> decimal,使用127.0.0.1
SELECT
TO_NUMBER(REGEXP_SUBSTR('127.0.0.1','\w+',1,1))*POWER(2,24)
+ TO_NUMBER(REGEXP_SUBSTR('127.0.0.1','\w+',1,2))*POWER(2,16)
+ TO_NUMBER(REGEXP_SUBSTR('127.0.0.1','\w+',1,3))*POWER(2,8)
+ TO_NUMBER(REGEXP_SUBSTR('127.0.0.1','\w+',1,4))*POWER(2,0) IP
FROM
DUAL;
一个有效的IP地址不能包含大于“255”(它是一个32位值)的部分。那里不能有'698'或'365'。 – dasblinkenlight 2013-02-21 03:44:07
是的..这个我只是一个例子,我加了 – 2013-02-21 03:44:53