SQL 插入 3 时“ORA-01438:值大于此列允许的指定精度”

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

"ORA-01438: value larger than specified precision allowed for this column" when inserting 3

sqloracle

提问by Luis Sep

I'm running into that error when trying to insert any number except 0 into a field with format NUMBER (2,2).

尝试将除 0 以外的任何数字插入到格式为 NUMBER (2,2) 的字段中时,我遇到了该错误。

UPDATE
    PROG_OWN.PROG_TPORCENTAJE_MERMA
SET
    PCT_MERMA = 3
WHERE
    IDN_PORCENTAJE_MERMA = 1

[Error Code: 1438, SQL State: 22003] ORA-01438: value larger than specified precision allowed for this column

[错误代码:1438,SQL 状态:22003] ORA-01438:该列允许的值大于指定的精度

COLUMN_NAME DATA_TYPE   TYPE_NAME   COLUMN_SIZE   BUFFER_LENGTH   DECIMAL_DIGITS
PCT_MERMA   3           NUMBER      2             0               2

It also happens if I try with decimal numbers.

如果我尝试使用十进制数,也会发生这种情况。

Any idea why?

知道为什么吗?

回答by TechDo

You can't update with a number greater than 1 for datatype number(2,2)is because, the first parameter is the total number of digits in the number and the second one (.i.e 2 here) is the number of digits in decimal part. I guess you can insert or update data < 1. i.e. 0.12, 0.95 etc.

对于数据类型number(2,2),您不能使用大于 1 的数字进行更新,因为第一个参数是数字中的总位数,第二个参数(此处为 2)是小数部分的位数。我猜你可以插入或更新数据< 1。即 0.12、0.95 等。

Please check NUMBER DATATYPE in NUMBER Datatype.

请检查NUMBER Datatype中的NUMBER DATATYPE

回答by Joachim Isaksson

NUMBER (precision, scale)means precisionnumber of total digits, of which scaledigits are right of the decimal point.

NUMBER (precision, scale)表示precision总位数,其中scale位数在小数点右边。

NUMBER(2,2)in other words means a number with 2 digits, both of which are decimals. You may mean to use NUMBER(4,2)to get 4 digits, of which 2 are decimals. Currently you can just insert values with a zero integer part.

NUMBER(2,2)换句话说就是一个2位数的数字,都是小数。您可能想使用NUMBER(4,2)来获取 4 位数字,其中 2 位是小数。目前,您只能插入整数部分为零的值。

More info at the Oracle docs.

Oracle 文档中的更多信息