Oracle NUMBER 数据类型中的精度和小数位数是什么意思

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

What does precision and scale means in the Oracle NUMBER data type

oracleoracle10goracle11gsqldatatypes

提问by KItis

I have been reading Beginners guide for oracle DB. The definition for precision and scale are quite confusing. Book says:

我一直在阅读 oracle DB 的初学者指南。精度和规模的定义非常混乱。书上说:

number(6,3) 

Oracle allows for 2 not 6 significant digitalis.

my problem is, 6 means precision. which means number of significant digits. so it should accept 6 significant digits. why does the book says it is 2 significant digits

我的问题是,6 表示精度。这意味着有效数字的数量。所以它应该接受6位有效数字。为什么书上说是两位有效数字

The book i am referring to is Oracle Database 11g A Beginner's Guide by McGraw Hill Professional, Dec 18, 2008, page number 12

我指的这本书是McGraw Hill Professional 所著的 Oracle Database 11g A Beginner's Guide,2008 年 12 月 18 日,第 12 页

采纳答案by Glenn

Check out the online Oracle doc:

查看在线 Oracle文档

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.

p 是精度,或有效十进制数字的最大数目,其中最高有效数字是最左边的非零数字,最低有效数字是最右边的已知数字。Oracle 保证数字的可移植性,精度高达 20 个以 100 为基数的数字,根据小数点的位置,相当于 39 位或 40 位十进制数字。

s 是小数位数,或从小数点到最低有效数字的位数。范围可以从 -84 到 127。

正数是小数点右侧的有效数字位数,包括最低有效数字。

负数是小数点左边的有效数字位数,但不包括最低有效数字。对于负刻度,最低有效数字位于小数点左侧,因为实际数据四舍五入到小数点左侧指定的位数。例如,(10,-2​​) 的规范意味着四舍五入到数百。