Avoid inserting exponential value in DB Float column

后端 未结 2 1187
离开以前
离开以前 2021-01-27 09:32

I have a table like

CONTACT

Name                           Null     Type                                                                                                


        
2条回答
  •  天命终不由人
    2021-01-27 09:49

    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'.

提交回复
热议问题