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
606 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
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.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

762 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

19 Experts available now in Live!

Get 1:1 Help Now