2017-10-16 526 views
2

我试图在SQL命令 此行运行,这是我的计划:甲骨文 - ORA-06502:PL/SQL:数字或值错误:数字精度太大

set verify off; 
set serveroutput on; 

prompt 
prompt 
prompt ======================================== 
prompt   E O N MULTIPLANETARY SYSTEM 
prompt ======================================== 
prompt 

accept inputstarname prompt "Enter the name of the star: " 
accept inputdistance prompt "Enter the light year distance: " 
accept inputspectral prompt "Enter the spectral type: " 
accept inputmass prompt "Enter the mass: " 
accept inputtemp prompt "Enter the temperature(kelvin): " 
accept inputage prompt "Enter the age (Giga Year): " 
accept inputconplanets prompt "Enter the confirmed planets: " 
accept inputunconplanets prompt "Enter the unconfirmed planets: " 
accept inputconstellation prompt "Enter the name of the constellation: " 

DECLARE 
    starname varchar2(20); 
    distance number(10,2); 
    spectral varchar2(10); 
    mass number(2,4); 
    temp int; 
    age number(3,5); 
    conplanets int; 
    unconplanets int; 
    constellation varchar(25); 
BEGIN 
    starname:='&inputstarname'; 
    distance:='&inputdistance'; 
    spectral:='&inputspectral'; 
    mass:='&inputmass'; 
    temp:='&inputtemp'; 
    age:='&inputage'; 
    conplanets:='&inputconplanets'; 
    unconplanets:='&inputunconplanets'; 
    constellation:='&inputconstellation'; 
    INSERT INTO eonmultiplanetarysystem (ID, STAR_NAME, DISTANCE_LY, SPECTRAL_TYPE, MASS, TEMPERATURE_K, AGE, CONFIRMED_PLANETS, UNCONFIRMED_PLANETS, CONSTELLATION) VALUES (eonmultiplanetarysystem_seq.nextval, starname, distance, spectral, mass, temp, age, conplanets, unconplanets, constellation); 
    commit; 
    dbms_output.put_line(chr(20)||'Successfully Added!'); 
END; 
/
prompt 
prompt 
@c:/CS325/index 

我的问题是这样的即使我改变输入我得到这个错误:

DECLARE 
* 
ERROR at line 1: 
ORA-06502: PL/SQL: numeric or value error: number precision too large 
ORA-06512: at line 15 

所以这是我输入 而这一点,我是想输入,我想这个问题是距离,所以我决定改变“1” “1.6。 你能帮我吗?

Enter the name of the star: Sun 
Enter the light year distance: 1.6 
Enter the spectral type: G2V 
Enter the mass: 1 
Enter the temperature(kelvin): 5778 
Enter the age (Giga Year): 4.572 
Enter the confirmed planets: 8 
Enter the unconfirmed planets: 1 
Enter the name of the constellation: None 
+0

让从基础开始:http://www.oracle.com/technetwork/issue-archive/ 2011/11-nov/o61plsql-512011.html。我建议你使用'PLS_INTEGER'或'SIMPLE_INTEGER',而不是'int'(因为这不是plsql),或者只是普通的旧NUMBER而没有精确性。其次,当输入如下数字时:'distance:='&inputdistance';',您可以将它作为距离:=&inputdistance ;,因为它会隐式地将字符串转换为数字,以便插入它。从这一点开始,请参阅您可能遇到的下一个问题,但请记住,您得到的错误是由精度引起的。 – g00dy

回答

1

age number(3,5)正在抛出错误。

这不能容纳4.572 要保持4.572,你必须将声明更改为数字(5,3)。这意味着该号码在该期间之前有两位数字,在该期间之后有三位数字。

0

问题与NUMBER数据类型有十进制精度。

在NUMBER数据类型中,第一个数字表示小数点两侧的总数位数,第二个数字表示小数点后的位数。

如:保留的34.34434值的数据类型应该是NUMBER(7,5)

谢谢:)