首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Oracle-Ora-06502: PL/SQL:数值或值错误:数字精度太大

Oracle-Ora-06502: PL/SQL:数值或值错误:数字精度太大
EN

Stack Overflow用户
提问于 2017-10-16 05:08:28
回答 2查看 6K关注 0票数 2

我试图在SQL命令行中运行这个程序--这是我的程序:

代码语言:javascript
复制
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

我的问题是,即使我改变了我的输入,我也会得到这个错误:

代码语言:javascript
复制
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’,你能帮我吗?

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-10-16 05:41:57

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

这不能容纳4.572以容纳4.572,您必须将声明更改为数字(5,3)。这意味着该数字将在期间之前有2位数,在期间之后有3位数。

票数 2
EN

Stack Overflow用户

发布于 2017-10-16 08:14:15

问题在于具有十进制精度的NUMBER数据类型。

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

要保存34.34434的值,数据类型应该是NUMBER(7,5)

谢谢:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46763301

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档