是"NUMBER"和"NUMBER(*,0)"在Oracle中一样吗? [英] Is "NUMBER" and "NUMBER(*,0)" the same in Oracle?
问题描述
在Oracle 文档中提到
In Oracle documentation it is mentioned that
NUMBER(精度,小数位数)
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
(不带精度和小数位数)也接受浮点数(34.30),但是根据文档,如果未指定scale,则默认情况下应为零小数位数,因此应仅允许整数,对吗?
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?.
在另一个问题中,提到
默认精度为38,默认比例为零
default precision is 38, default scale is zero
所以NUMBER
和NUMBER(*,0)
应该相等,但不相等.
So NUMBER
and NUMBER(*,0)
should be equal but they are not.
我在哪里错了?
推荐答案
小数位数的默认值不为零,其中没有任何值.因此,它可以接受-84 to 127
之间的任何值.如果将其限制为零,则即使该值包含小数位值
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
create table aaaaa
(
sno number(*,0),
sno1 number
);
user_tab_columns
将为您提供精度和小数位数的值
The user_tab_columns
will give you the value of your precision and scale
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>
请找到以下工作方式
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>
这篇关于是"NUMBER"和"NUMBER(*,0)"在Oracle中一样吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!