oracle的number和integer类型

bisal(Chen Liu)
博客专家认证
2011-01-31 12:22:10
oracle中integer和number类型
oracle中:
number(10)表示长度是10,

问题:
1、integer类型表示的number长度是53?(在oracle的create table中可以定义字段类型为Integer啊?)
2、那number类型表示的长度是否是默认的38?因为我看到有的文章说它的类型大于38。

谢谢!
...全文
28017 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
寒冰2046 2012-02-11
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 acmain_chm 的回复:]

为什么不看一下ORACLE的在线手册?

NUMBER [ (p [, s]) ] 是ORACLE自身的数据类型。

INTEGER或者INT、SMALLINT 则是 ANSI SQL 的数据类型,它对应的ORALCE数据类型是NUMBER(38)
[/Quote]这个好
Ny-6000 2011-12-08
  • 打赏
  • 举报
回复


study.
zty598416146 2011-02-21
  • 打赏
  • 举报
回复
integer 是number的一个别名 子集关系
yanran_hill 2011-02-09
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 xman_78tom 的回复:]
INT、INTEGER 是 NUMBER 的受限子类型(只表示整数),相当于 NUMBER(38)。

NUMBER 类型最大可表示 38 个十进制位的数值。
[/Quote]
话虽这么说,可实际应用中,应该还是有区别吧?
比如用pro*c编程,对应的number类型对应的C语言变量类型是double/float;
而INT 类型对应的C语言变量类型就是int了.
bisal(Chen Liu) 2011-02-09
  • 打赏
  • 举报
回复
1、http://blog.sina.com.cn/s/blog_4ac82fcf0100ii18.html

大家请看下上面这篇博文,里面讲到:
“以前我一直以为 integer=number(38,0) --38是number的最大精度
刚才无意中发现integer 是个超大的数据类型,最大可以表示为power(10,126)-1
...
一个integer类型最少使用53个字节”

2、“因为Oracle的表结构中没有布尔类型,所以很多人干脆用integer代替布尔类型,这个感觉有点“奢侈”;我一般都用char(1)表示布尔型;'0'表示false,'1'表示true”

这里我一般用NUMBER(1)来表示boolean类型,这种用法应该与使用char(1)占用的空间一样多吧?
ACMAIN_CHM 2011-02-01
  • 打赏
  • 举报
回复
[Quote]2、那number类型表示的长度是否是默认的38?因为我看到有的文章说它的类型大于38。[/Quote]

手册中关于NUMBER说明的最后一句话就是你要的答案。
[Quote]NUMBER [ (p [, s]) ]
Number having precision p and scale s. The precision p can range from 1 to 38. The scale s can range from -84 to 127. Both precision and scale are in decimal digits. A NUMBER value requires from 1 to 22 bytes.


NUMBER Data Type The NUMBER data type stores zero as well as positive and negative fixed numbers with absolute values from 1.0 x 10-130 to but not including 1.0 x 10126. If you specify an arithmetic expression whose value has an absolute value greater than or equal to 1.0 x 10126, then Oracle returns an error. Each NUMBER value requires from 1 to 22 bytes.

Specify a fixed-point number using the following form:

NUMBER(p,s)
where:

?p is the precision, or the maximum number of significant decimal digits, where the most significant digit is the left-most nonzero digit, and the least significant digit is the right-most known digit. Oracle guarantees the portability of numbers with precision of up to 20 base-100 digits, which is equivalent to 39 or 40 decimal digits depending on the position of the decimal point.

?s is the scale, or the number of digits from the decimal point to the least significant digit. The scale can range from -84 to 127.

?Positive scale is the number of significant digits to the right of the decimal point to and including the least significant digit.

?Negative scale is the number of significant digits to the left of the decimal point, to but not including the least significant digit. For negative scale the least significant digit is on the left side of the decimal point, because the actual data is rounded to the specified number of places to the left of the decimal point. For example, a specification of (10,-2) means to round to hundreds.

Scale can be greater than precision, most commonly when e notation is used. When scale is greater than precision, the precision specifies the maximum number of significant digits to the right of the decimal point. For example, a column defined as NUMBER(4,5) requires a zero for the first digit after the decimal point and rounds all values past the fifth digit after the decimal point.

It is good practice to specify the scale and precision of a fixed-point number column for extra integrity checking on input. Specifying scale and precision does not force all values to a fixed length. If a value exceeds the precision, then Oracle returns an error. If a value exceeds the scale, then Oracle rounds it.

Specify an integer using the following form:

NUMBER(p)
This represents a fixed-point number with precision p and scale 0 and is equivalent to NUMBER(p,0).

Specify a floating-point number using the following form:

NUMBER
The absence of precision and scale designators specifies the maximum range and precision for an Oracle number.

[/Quote]
ACMAIN_CHM 2011-02-01
  • 打赏
  • 举报
回复
为什么不看一下ORACLE的在线手册?

NUMBER [ (p [, s]) ] 是ORACLE自身的数据类型。

INTEGER或者INT、SMALLINT 则是 ANSI SQL 的数据类型,它对应的ORALCE数据类型是NUMBER(38)

  • 打赏
  • 举报
回复
来个中文的.NUMBER(prescision,scale)存储浮点数,但也可以用来存储整数.precision是这个数字可以使用的最大位数.如果使用小数,这些数字一部分在小数点之前(整数部分),一部分在小数点之后(小数部分).Oracle所支持的最大精度是38,如果使用小数,scale是小数点右边的最大位数.如果precision和scale都没有指定,那就可以存储38位精度的数字.精度超过precision不能存储到Oracle中.
INTEGER存储整数,整数不包括浮点数.是一个整数数字.
iihero_ 2011-01-31
  • 打赏
  • 举报
回复
1. Integer只是个别名。number才是实际类型
2. 是的
njlywy 2011-01-31
  • 打赏
  • 举报
回复
1.父子类的关系

2.是的
xman_78tom 2011-01-31
  • 打赏
  • 举报
回复
INT、INTEGER 是 NUMBER 的受限子类型(只表示整数),相当于 NUMBER(38)。

NUMBER 类型最大可表示 38 个十进制位的数值。

3,491

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧