SQL Oracle 中的“NUMBER”和“NUMBER(*,0)”是否相同?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28207708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is "NUMBER" and "NUMBER(*,0)" the same in Oracle?
提问by Rajeev
In Oracle documentationit is mentioned that
在 Oracle文档中提到
NUMBER (precision, scale)
If a precision is not specified, the column stores values as given. If no scale is specified, the scale is zero.
NUMBER(精度,比例)
如果未指定精度,则该列存储给定的值。如果未指定比例,则比例为零。
But NUMBER
(without precision and scale) is also accepting floating point numbers (34.30) but according to documentation if scale is not specified it should be zero scale by default so it should allow only integers, am I wrong?.
但是NUMBER
(没有精度和比例)也接受浮点数(34.30)但是根据文档,如果没有指定比例,默认情况下应该是零比例,所以它应该只允许整数,我错了吗?。
And in another questionsit is mentioned that
在另一个问题中提到
default precision is 38, default scale is zero
默认精度为 38,默认比例为零
So NUMBER
and NUMBER(*,0)
should be equal but they are not.
所以NUMBER
和NUMBER(*,0)
应该是平等的,但他们不是。
Where am I wrong?
我哪里错了?
回答by David Faber
I think the sentence in the documentation
我认为文档中的句子
If a precision is not specified, the column stores values as given. If no scale is specified, the scale is zero.
如果未指定精度,则该列存储给定的值。如果未指定比例,则比例为零。
is a bit confusing. The scale is zero if a precision is specified and a scale is not specified. So, for example, NUMBER(19)
is equivalent to NUMBER(19,0)
. NUMBER
, by itself, will have 38 digits of precisionbut no defined scale. So a column defined as a NUMBER
can accept values of anyscale, as long as their precision is 38 digits or less (basically, 38 numerical digits with a decimal point in any place).
有点混乱。如果指定了精度而未指定小数位数,则小数位数为零。因此,例如,NUMBER(19)
相当于NUMBER(19,0)
。NUMBER
本身将具有 38 位精度,但没有定义的scale。因此,定义为 a 的列NUMBER
可以接受任何比例的值,只要它们的精度为 38 位或更少(基本上,38 位数字在任何位置都有小数点)。
You can also specify a scale without a precision: NUMBER(*, <scale>)
, but that just creates the column with 38 digits of precision so I'm not sure it's particularly useful.
您也可以指定一个没有 precision: 的比例尺NUMBER(*, <scale>)
,但这只会创建具有 38 位精度的列,所以我不确定它是否特别有用。
The table How Scale Factors Affect Numeric Data Storageon this pagemight be helpful.
此页面上的比例因子如何影响数值数据存储表可能会有所帮助。
回答by Exhausted
The default of scale is not zero, which has no value in it. Hence it can accept any value between -84 to 127
. If you limit it to zero then it will not accept any presicion even the value contains the scale value
scale 的默认值不为零,其中没有任何值。因此它可以接受 之间的任何值-84 to 127
。如果您将其限制为零,则即使该值包含比例值,它也不会接受任何 presicion
create table aaaaa
(
sno number(*,0),
sno1 number
);
The user_tab_columns
will give you the value of your precision and scale
该user_tab_columns
给你的你的精度和标度值
SQL> select column_name,data_precision,data_scale from user_tab_columns where ta
ble_name = 'AAAAA';
COLUMN_NAME DATA_PRECISION DATA_SCALE
------------------------------ -------------- ----------
SNO 0
SNO1
SQL>
Please find the below workings
请找到以下工作
SQL> select * from aaaaa;
no rows selected
SQL> insert into aaaaa values (123.123123,123123.21344);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from aaaaa;
SNO SNO1
---------- ----------
123 123123.213
SQL>
回答by Marmite Bomber
This parts of Oracle documentationmakes it absolutely clear:
Oracle 文档的这一部分非常清楚:
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).
使用以下形式指定一个整数:
数量(p)
这表示精度为 p 且标度为 0 的定点数,等效于 NUMBER(p,0)。
and
和
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.
使用以下形式指定一个浮点数:
数字
缺少精度和小数位指示符指定 Oracle 数字的最大范围和精度。
The meaning of the starprecision is documented hereand means the precision of 38
星形精度的含义记录在此处,表示 38 的精度