Solved

How do I copy data from one FLOAT column in Table A to another in Table B without loss of data precision?

Posted on 2008-10-14
7
608 Views
Last Modified: 2013-12-19
Using Oracle 9.
In the same database, I wish to copy the values of Column A  in Table 1 that is formatted as FLOAT (22) into Column A of Table 2 that is also formatted as FLOAT (22). But when I try to do so, I get a loss in precision of the value.

For example, a value of 7393.80896668582 ends up as a value of 7393.809 ???

Tried several ways to do this.
1. Straight INSERT INTO Table 2 (Col A) select (Col A) from Table 2
2. Run query to extract rows from Table 1..... use TO_CHAR (Col A) ..... this correctly gives the right precision in the dumped csv or xls file..... then load data into Table 2.... same loss of precision...

Browsing for answers, this is what I'm concluding:

1. Something to do with the Oracle ODBC driver not handling things correctly? (Oracle ODBC driver 9.02.00.65). [And, by the way, PC is running Windows 2000 SP4]

2. That I need to jump through many more hoops, eg: CAST the orignal FLOAT value as VARCHAR, then CAST the VARCHAR as a NUMBER.... (and here I'm thinking NUMBER FLOATING).... then try again.... my problem here is that I'm not sure of the syntax.... eg NUMBER (x, y) ... what should the x,y values be? What is the syntax for NUMBER...FLOATING? And, anyway, is this valid ? will this work ?

3. That I'm a total idiot

Hopefully the answer is 3, because I cannot believe there is not a simple way to do this?

And it's urgent, coz I've gotta rescue data on a live system....

Appreciate any help here.

Rgds
Jack
0
Comment
Question by:quaylochjack
  • 4
  • 3
7 Comments
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 22711688
can you please try without the () on the select side?



>1. Something to do with the Oracle ODBC driver not handling things correctly? (Oracle ODBC driver 9.02.00.65). [And, by the way, PC is running Windows 2000 SP4]
no, as the SQL INSERT ... SELECT will not bring the data to the client, actually, it will be entirely handled by the server engine

2. we will see later, if below suggestion does not work

3. I don't think so :)

1. Straight INSERT INTO Table 2 (Col A) select Col_A from Table 2

Open in new window

0
 

Author Comment

by:quaylochjack
ID: 22711899
angelll..... thanks.. but I was just using short-hand to describe the issue.... I did use the correct syntax...

Insert into Table 1
       (Col A)
Select
       Col A
from Table 2
0
 

Author Comment

by:quaylochjack
ID: 22711953
So just to be clear...... using the correct INSERT INTO syntax did not work.... I lost precision....
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 22711979
what is the exact version of the oracle server, please?
also, can you show the DESCRIBE of the 2 tables?
finally, what about:
INSERT INTO Table 2 (Col A) select cast(cast(Col_A as number(26,20)) as float) from Table 2

Open in new window

0
 

Author Comment

by:quaylochjack
ID: 22712186
angellll: tried
INSERT INTO Table 2 (Col A) select cast(cast(Col_A as number(26,20)) as float) from Table 2
 Still same problem --> only 3 decimal places.....

Oracle database version : 09.02.0080

Describe? What do you need here?

0
 

Accepted Solution

by:
quaylochjack earned 0 total points
ID: 22719418
Ok...managed to solve my problem..... here's the story..

I needed to create a lookup table. In doing so, I simply looked at the properties / data types of columns in existing "live" tables in the db to specify my CREATE TABLE sql. So, for the FLOAT columns I saw that these were FLOAT (22) and duly I added a line in my CREATE TABLE script:
                        CREATE TABLE TABLE 1
                        ( Column 1 NVARCHAR 2 (60),
                          Column 2 CHAR (10),
                          <....>,
                         Column x FLOAT (22),
                          < etc>)
When I did this, I got the problem with trying to copy (INSERT INTO) the table. The "float data" that I loaded lost precision.
So, I modified the CREATE TABLE script, and this time did not specify a precision for the FLOAT column - in other words, just let Oracle handle it:
                         Column x FLOAT,
                         <etc>)
Now when I looked at the table properties after running the CREATE TABLE sql, sure enough Oracle "did" handle it - and showed the data type to be FLOAT (22)..... by default?
Now when I ran my straight forward INSERT INTO script, sure enough the "float data" came across fine..
[And note, it was the simple INSERT INTO script... I did not need to CAST anything to anything].

So.... problem sorted......although I'm not sure I understand what Oracle does here.......

Meanwhile thank you for your help anyway....

Rgds
Jack
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22719608
coool!

>.although I'm not sure I understand what Oracle does here.......
what interface did you use to see the FLOAT(22), actually?
I assume the problem lies there...

CHeers
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server syntax question 13 32
Oracle - Query link database loop 8 39
SQL Insert parts by customer 12 34
Query Syntax 17 36
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Via a live example, show how to take different types of Oracle backups using RMAN.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

803 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