Solved

Updating a NUMBER datatype with a decimal value in Oracle

Posted on 2014-10-22
3
1,134 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
ID: 40397833
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)
ID: 40398138
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
ID: 40399420
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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 with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

920 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

14 Experts available now in Live!

Get 1:1 Help Now