"NUMBER" 和 "NUMBER(*,0)" 在 Oracle 中是否相同?

Is "NUMBER" and "NUMBER(*,0)" the same in Oracle?

在 Oracle documentation 中提到

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) 但根据文档,如果未指定小数位数,则默认情况下应该为零小数位数,因此它应该只允许整数,我我错了吗?

并且在 another questions 中提到

default precision is 38, default scale is zero

所以 NUMBERNUMBER(*,0) 应该相等,但它们不是。

我哪里错了?

scale的默认值不是零,里面没有值。因此它可以接受 -84 to 127 之间的任何值。如果将其限制为零,那么即使该值包含比例值

,它也不会接受任何预测
create table aaaaa
(
sno number(*,0),
sno1 number
);

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>

请找出下面的工作原理

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>

我认为文档中的句子

If a precision is not specified, the column stores values as given. If no scale is specified, the scale is zero.

有点混乱。如果指定了精度但未指定小数位数,则小数位数为零 。因此,例如,NUMBER(19) 等同于 NUMBER(19,0)NUMBER 本身将有 38 位 precision 但没有定义 scale。因此,定义为 NUMBER 的列可以接受 任何 比例的值,只要它们的精度为 38 位或更小(基本上,38 位数字在任何地方)。

您也可以指定一个没有精度的比例:NUMBER(*, <scale>),但这只会创建具有 38 位精度的列,所以我不确定它是否特别有用。

table 比例因子如何影响数值数据存储 this page 可能会有帮助。

Oracle documentation 的这一部分非常清楚:

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.

星号 精度的含义已记录 here 并且表示 38

的精度

另一个松鼠案例,但我遇到过...如果您要插入的 table 包含触发器,您可能应该检查它的任何程序流程是否包括尝试将某些内容转换为数字。 ..