避免在DB Float列中插入指数值 [英] Avoid inserting exponential value in DB Float column

查看:220
本文介绍了避免在DB Float列中插入指数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于
$ b

 联系人

的表格
- ---------------------------- -------- -----------
CONTACT_ID NOT NULL NUMBER
NAME NOT NULL VARCHAR2(45)
EMAIL NOT NULL VARCHAR2(45)
ADDRESS NOT NULL VARCHAR2(45)
TELEPHONE NOT NULL VARCHAR2(45)
AMOUNT NOT NULL FLOAT(126)

,插入语句为:

 插入联系人(CONTACT_ID, NAME,EMAIL,ADDRESS,TELEPHONE,AMOUNT)
values('36','babusailesh1117777','hainatu1@gmail.com','Vietnam1',
'0904277091', '0.0000000555559080767');

当我看到数据库中插入的最终值时,我看到了一个指数值。



如何避免在数据库级别的所有表?

解决方案

不存储为指数,它存储在Oracle的内部数字表示中。当您查询它时,会显示您的会话的当前数字格式:

 从双重选择0.0000000555559080767; 

0.0000000555559080767
------------------------------------- -
5.6E-08

您可以在SQL * Plus或SQL Developer中重写:

  set numformat 999.9999999999999999999 
从dual中选择0.0000000555559080767;

0.0000000555559080767
------------------------
.0000000555559080767


$ b

或者将值明确地格式化为一个字符串,仅供显示:

  set numf
从dual中选择to_char(0.0000000555559080767,'9990.9999999999999999999');

TO_CHAR(0.000000055555908
-------------------------
0.0000000555559080767

如果您有一个客户端应用程序检索并使用该值,则应该将其查询为一个浮点数,客户端的语言,然后它是如何显示的客户端。






你也不应该插入一个字符串进入浮动列,只是做一个隐式的转换;插入的最后一个参数应该是 0.0000000555559080767 而不是引用的'0.0000000555559080767'


I have a table like

CONTACT

Name                           Null     Type                                                                                                                                                                                          
------------------------------ -------- -----------
CONTACT_ID                     NOT NULL NUMBER                                                                                                                                                                                        
NAME                           NOT NULL VARCHAR2(45)                                                                                                                                                                                  
EMAIL                          NOT NULL VARCHAR2(45)                                                                                                                                                                                  
ADDRESS                        NOT NULL VARCHAR2(45)                                                                                                                                                                                  
TELEPHONE                      NOT NULL VARCHAR2(45)                                                                                                                                                                                  
AMOUNT                         NOT NULL FLOAT(126) 

and the insert statement is:

Insert into  contact("CONTACT_ID","NAME","EMAIL","ADDRESS","TELEPHONE","AMOUNT")
values ('36','babusailesh1117777','hainatu1@gmail.com','Vietnam1',
  '0904277091','0.0000000555559080767');

When I see the final value inserted in the database, I see an exponential value.

How can I avoid this at database level for all tables?

解决方案

It isn't stored as an exponential, it's stored in Oracle's internal number representation. When you query it, it's displayed with your sessions's current number format:

select 0.0000000555559080767 from dual;

                  0.0000000555559080767
---------------------------------------
                                5.6E-08

Which you can override in SQL*Plus or SQL Developer:

set numformat 999.9999999999999999999
select 0.0000000555559080767 from dual;

   0.0000000555559080767
------------------------
    .0000000555559080767

Or explicitly format the value as a string, for display only:

set numf ""
select to_char(0.0000000555559080767, '9990.9999999999999999999') from dual;

TO_CHAR(0.000000055555908
-------------------------
    0.0000000555559080767

If you have a client application retrieving and using the value then it should query it as a float, into a suitable data type for the client's language, and then it's up to the client how it's displayed.


You also shouldn't be inserting a string into the float column, that just does an implicit conversion; the last argument in your insert should be 0.0000000555559080767 rather than the quoted '0.0000000555559080767'.

这篇关于避免在DB Float列中插入指数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆