Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Oracle SQL表中存储IP地址_Sql_Database_Oracle_Ip Address - Fatal编程技术网

在Oracle SQL表中存储IP地址

在Oracle SQL表中存储IP地址,sql,database,oracle,ip-address,Sql,Database,Oracle,Ip Address,我已经创建了一个表来存储IP地址 创建表ipdetails ip_地址小数16,4不为空, vlan_id varchar50 ; 但当我尝试插入到表中时,它会给我一个错误: INSERT INTO ipdetails VALUES (192.169.165.128, 'Sample1') 我是否可以在SQL表中存储一个小数点很多的数字,如果可以,我应该使用什么数据类型?请给我一些建议 提前谢谢 您有几种选择: 将其存储为VARCHAR。IP地址并不是一个你们可能会用到的数字,那个么为什么要

我已经创建了一个表来存储IP地址

创建表ipdetails ip_地址小数16,4不为空, vlan_id varchar50 ;

但当我尝试插入到表中时,它会给我一个错误:

INSERT INTO ipdetails VALUES (192.169.165.128, 'Sample1')
我是否可以在SQL表中存储一个小数点很多的数字,如果可以,我应该使用什么数据类型?请给我一些建议


提前谢谢

您有几种选择:

将其存储为VARCHAR。IP地址并不是一个你们可能会用到的数字,那个么为什么要用数字格式存储它呢? 将其作为单个数字存储在十六进制中。虽然你不能用十进制来表示,但在十六进制中,IP是一个8位数字。 最多可将其存储为四个单独的字段。可能不必要,但对于某些应用程序,您可能希望主要只关注IP的一部分,这可能很有用。
您有几个选择:

将其存储为VARCHAR。IP地址并不是一个你们可能会用到的数字,那个么为什么要用数字格式存储它呢? 将其作为单个数字存储在十六进制中。虽然你不能用十进制来表示,但在十六进制中,IP是一个8位数字。 最多可将其存储为四个单独的字段。可能不必要,但对于某些应用程序,您可能希望主要只关注IP的一部分,这可能很有用。
尝试将值存储为字符串并使用引号:

CREATE TABLE ipdetails( ip_address varchar(15) NOT NULL, vlan_id varchar(50) );
然后

INSERT INTO ipdetails VALUES ('192.169.698.365', 'Sample1')

您可能希望将每个组件存储在单独的字段中。

尝试将值存储为字符串并使用引号:

CREATE TABLE ipdetails( ip_address varchar(15) NOT NULL, vlan_id varchar(50) );
然后

INSERT INTO ipdetails VALUES ('192.169.698.365', 'Sample1')

您可能希望将每个组件存储在单独的字段中。

您可以将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);

您可以将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);

有效的IP地址不能包含大于255的部分。它是一个32位的值。那里不能有698或365。是。。这只是一个例子,我添加了一个有效的IP地址不能包含大于255的部分,这是一个32位的值。那里不能有698或365。是。。这只是我为回复添加的一个示例,我只是想知道SQL中是否有一种数据类型来存储小数位数很多的数字?@frozenhaart不幸的是,没有这样的内在数据类型。没有比小数点多一个的数字数据类型。IP地址实际上是一个复合数字。每个存储选项都有缺点,比如排序语义和范围查询。IP地址中的句点不是小数。它们只是字段分隔符;写192:168:213:153而不是点也是合法的。。谢谢你的澄清!感谢您的回复,我只是想知道SQL中是否有一种数据类型可以存储小数位数很多的数字?@frozenhaart不幸的是,没有这种内在的数据类型。没有比小数点多一个的数字数据类型。IP地址实际上是一个复合数字。每个存储选项都有缺点,比如排序语义和范围查询。IP地址中的句点不是小数。它们只是字段分隔符;写192:168:213:153而不是点也是合法的。。谢谢你的澄清!