Solved

Updating a NUMBER datatype with a decimal value in Oracle

Posted on 2014-10-22
3
1,007 Views
Last Modified: 2014-10-23
How do I update a datatype NUMBER with a decimal value?

UPDATE myTable SET myNumberVal=0.07

Open in new window


and

UPDATE myTable SET myNumberVal='0.07'

Open in new window


both result in the value being updated as "0"
0
Comment
Question by:mwmiller78
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
Comment Utility
The first one is correct.  If you cannot see the decimal places it is one of two issues:
The table does not allow decimal places or what you are using to query it isn't showing them.

Post the results of:
desc myTable ;


If the column is a whole number like number(10), then you cannot store decimals.

It would need to be defined as something like number(12,2).
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
Here it is in action:
SQL> drop table tab1 purge;

Table dropped.

SQL> create table tab1(col1 number);

Table created.

SQL>
SQL> insert into tab1 values(.07);

1 row created.

SQL> select * from tab1;

      COL1
----------
       .07

SQL> rollback;

Rollback complete.

SQL>
SQL> alter table tab1 modify col1 number(10);

Table altered.

SQL> insert into tab1 values(.07);

1 row created.

SQL> select * from tab1;

      COL1
----------
         0

SQL> rollback;

Rollback complete.

SQL>
SQL> alter table tab1 modify col1 number(12,2);

Table altered.

SQL> insert into tab1 values(.07);

1 row created.

SQL> select * from tab1;

      COL1
----------
       .07

Open in new window

0
 

Author Closing Comment

by:mwmiller78
Comment Utility
That's what it was. I copied this table from another server and the precision/scale didn't copy over with it. Thanks!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now