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
610 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 143

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 143

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 143

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

685 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