您可以将 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,它使用 127.0.0.1 执行其中一个执行 ip->decimal 的操作
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;