oracle 精度和规模有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5689369/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 03:13:25  来源:igfitidea点击:

What is the difference between precision and scale?

oracletypes

提问by user700792

What is the difference between precision and scale in Oracle? In tutorials they usually leave scale empty and set precision to 6 when creating a primary key.

Oracle 中的精度和小数位数有什么区别?在教程中,他们通常在创建主键时将 scale 留空并将精度设置为 6。

What do precision and scale stand for?

精度和规模代表什么?

回答by koljaTM

Precision 4, scale 2: 99.99

精度 4,刻度 2:99.99

Precision 10, scale 0: 9999999999

精度 10,比例 0:9999999999

Precision 8, scale 3: 99999.999

精度 8,刻度 3:99999.999

Precision 5, scale -3: 99999000

精度 5,刻度 -3:99999000

回答by manojlds

Precision is the number of significant digits. Oracle guarantees the portability of numbers with precision ranging from 1 to 38.

精度是有效数字的位数。Oracle 以 1 到 38 的精度保证数字的可移植性。

Scale is the number of digits to the right (positive) or left (negative) of the decimal point. The scale can range from -84 to 127.

小数位数是小数点右侧(正)或左侧(负)的位数。范围可以从 -84 到 127。

In your case, ID with precision 6 means it won't accept a number with 7 or more significant digits.

在您的情况下,精度为 6 的 ID 意味着它不会接受具有 7 个或更多有效数字的数字。

Reference:

参考:

http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1832

http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1832

That page also has some examples that will make you understand precision and scale.

该页面还有一些示例,可以让您了解精度和比例。

回答by Ayman

Precisionis the total number of digits, can be between 1 and 38.
Scaleis the number of digits after the decimal point, may also be set as negative for rounding.

Precision是总位数,可以在 1 到 38 之间。
scale是小数点后的位数,也可以设置为负数进行四舍五入。

Example:
NUMBER(7,5): 12.12345
NUMBER(5,0): 12345

示例:
NUMBER(7,5): 12.12345
NUMBER(5,0): 12345

More details on the ORACLE website:
https://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1832

ORACLE 网站上的更多详细信息:https:
//docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1832

回答by Eric Bole-Feysot

Maybe more clear:

也许更清楚:

Note that precision is the total number of digits, scale included

请注意,精度是总位数,包括小数位数

NUMBER(Precision,Scale)

Precision 8, scale 3 : 87654.321

Precision 5, scale 3 : 54.321

Precision 5, scale 1 : 5432.1

Precision 5, scale 0 : 54321

Precision 5, scale -1: 54320

Precision 5, scale -3: 54000

NUMBER(精度,刻度)

精度 8,刻度 3:87654.321

精度 5,刻度 3:54.321

精度 5,刻度 1:5432.1

精度 5,比例 0:54321

精度 5,比例 -1:54320

精度 5,比例 -3:54000

回答by ylerjen

Scale is the number of digit after the decimal point (or colon depending your locale)

比例是小数点后的位数(或冒号,取决于您的语言环境)

Precision is the total number of significant digits

精度是有效数字的总数

scale VS precision

规模 VS 精度

回答by Bablu Gope

precision: Its the total number of digits before or after the radix point. EX: 123.456 here precision is 6.

精度:小数点前后的总位数。例如:123.456 这里的精度是 6。

Scale: Its the total number of digits after the radix point. EX: 123.456 here Scaleis 3

小数位数:小数点后的总位数。EX: 123.456 这里 Scaleis 3

回答by yogi

If value is 9999.988 and Precision 4, scale 2 then it means 9999(it represents precision).99(scale is 2 so .988 is rounded to .99)

如果值为 9999.988 且精度为 4,比例为 2,则表示 9999(表示精度)。99(比例为 2,因此 .988 舍入为 0.99)

If value is 9999.9887 and precision is 4, scale is 2 then it means 9999.99

如果值为 9999.9887 且精度为 4,小数位数为 2,则表示 9999.99