在Oracle SQL表中存储IP地址 [英] Storing an IP Address in a Oracle SQL Table

查看:1046
本文介绍了在Oracle SQL表中存储IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



CREATE TABLE ipdetails(
ip_address DECIMAL(16,4)NOT NULL,
vlan_id varchar(50)
);



但是当我尝试插入到表中时我错误:

  INSERT INTO ipdetails VALUES(192.169.165.128,'Sample1')

有没有反正我可以存储一个数字与十进制小数位数在SQL表中,如果是这样,我应该使用什么数据类型?

解决方案

您有几个选项:




  • 将其存储为VARCHAR。 IP地址实际上不是你可能做的数字,所以为什么要以数字格式存储?

  • 将十六进制作为单个数字存储。虽然你不能真正做到十进制,在十六进制的IP是一个8位数字。

  • 将它存储为(最多)四个单独的字段。可能是不必要的,但对于某些应用程序(您可能希望主要只关心IP的一部分)。这可能是有用的。


I have created a table to store IP addresses.

CREATE TABLE ipdetails( ip_address DECIMAL(16,4) NOT NULL, vlan_id varchar(50) );

But when i try to insert into the table it gives me an error :

INSERT INTO ipdetails VALUES (192.169.165.128, 'Sample1')

Is there anyway i could store a number with lot of decimal places in a SQL table, if so what is the Data Type i should use? Please advice.

Thanks in Advance!

解决方案

You have several options:

  • Store it as a VARCHAR. IP address isn't really a number you're likely to do math on, so why store it in numeric format?
  • Store it in hexidecimal as a single number. While you can't really do that in decimal, in hexidecimal an IP is an 8 digit number.
  • Store it as (up to) four separate fields. Probably unnecessary but for certain applications (where you might want to primarily only be concerned with one part of the IP) this could be useful.

这篇关于在Oracle SQL表中存储IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆