PL/SQL 数字或值错误:数字精度太大
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9012779/
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
PL/SQL numeric or value error: number precision too large
提问by atrueresistance
I've got a oracle 10g PL/SQL program that I'm trying to get to run,
我有一个试图运行的 oracle 10g PL/SQL 程序,
Program
程序
set serveroutput on size 10000;
DECLARE
membership varchar2(1) :='Y';
shipping number(2,2);
quantity number(3) :=0;
BEGIN
if membership = 'Y' then
if quantity <= 3 then
shipping := 3.00;
elsif quantity > 3 and quantity <= 6 then
shipping := 5.00;
elsif quantity > 6 and quantity <= 10 then
shipping := 7.00;
elsif quantity > 10 then
shipping := 9.00;
end if;
elsif membership = 'N' then
if quantity <= 3 then
shipping := 5.00;
elsif quantity > 3 and quantity <= 6 then
shipping := 7.50;
elsif quantity > 6 and quantity <= 10 then
shipping := 10.00;
elsif quantity > 10 then
shipping := 12.00;
end if;
end if;
DBMS_OUTPUT.PUT_LINE(shipping);
END;
The error I keep getting. At first I thought it was just because I was assigning quantity to a number(3), so then I would compare with 003 but that didn't work either.
我不断收到的错误。起初我认为这只是因为我将数量分配给一个数字(3),所以我会与 003 进行比较,但这也不起作用。
Error report:
ORA-06502: PL/SQL: numeric or value error: number precision too large
ORA-06512: at line 8
06502. 00000 - "PL/SQL: numeric or value error%s"
*Cause:
*Action:
回答by Derek Kromm
Try changing shipping number(2,2)
to shipping number(4,2)
尝试更改shipping number(2,2)
为shipping number(4,2)
(2,2) is basically saying that you want 2 digits and 2 of them are after the decimal point. So your range of values is 0 through 0.99. What you really want is "4 digits, 2 of which are after the decimal" which ranges from 0 through 99.99.
(2,2) 基本上是说你想要 2 位数字,其中 2 位在小数点后。所以你的值范围是 0 到 0.99。您真正想要的是“4 位数字,其中 2 位在小数点之后”,范围从 0 到 99.99。