我试图在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至' 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 :(得分:1)
age number(3,5)
正在抛出错误。
这不能容纳4.572 要保留4.572,您必须将声明更改为数字(5,3)。这意味着该数字在该期间之前将具有2位数字,并且在该期间之后具有3位数字。
答案 1 :(得分:0)
问题在于具有小数精度的NUMBER
数据类型。
在NUMBER数据类型中,第一个数字表示小数点两边的总位数,第二个数字表示小数点后的位数。
例如:要保持值34.34434
,数据类型应为NUMBER(7,5)
谢谢:)