Link to home
Start Free TrialLog in
Avatar of Peter Thaller
Peter Thaller

asked on

Decimals Lost When Selecting Data From Database Link

Hi!
I have a similar problem like https://www.experts-exchange.com/questions/26668199/Decimals-Lost-When-Selecting-Data-From-Database-Link.html.

On MS SQL Server I have a View with a type decimal(9,6). When I create a view on ORACLE to that View on MS SQL I get a type NUMBER(18,2) but the numbers are cutted.
0.980340 gets 0!

When I make a multiplication with 100000 i get 980340.
When I make to_char (var * 1000000,'999999') it say's 0!!

Can You help me?
Thanks Peter
Avatar of Mark Geerlings
Mark Geerlings
Flag of United States of America image

"When I make a multiplication with 100000 i get 980340."
That makes it look like the decimal values are not actually gone, just hidden
Can you do: "alter session set numformat 999999.999999;
Which Oracle tool are you viewing this data with?
.

"When I make to_char (var * 1000000,'999999') it say's 0!!"
Yes, because your format mask: '999999' tells Oracle to hide the decimal digits.

What do you get if you try this format mask instead?
to_char (var * 1000000,'9999999.9999999')
When I create a view on ORACLE to that View on MS SQL I get a type NUMBER(18,2) but the numbers are cutted.

For the Oracle view data type to be NUMBER(18, 6) rather than 18, 2.  In the view def, use a CAST to force the data type of that column if you need to.
>>When I make to_char (var * 1000000,'999999') it say's 0!!

Does this make a difference?
When I make to_char (var * 1000000.0,'999999')
Does this make a difference?
When I make to_char (var * 1000000.0,'999999')
It shouldn't.  There is no part of your format string after the decimal place, so anything after the decimal will not be displayed.
@johnsone
There is a difference between integer multiplication and floating point multiplication.  Note I changed an integer to a floating point.  (I'm not really expecting any difference but eliminating obvious problems in a simple manner is also helpful in finding out what is happening).

To be honest I am expecting the database actually stores zero not the value given in the question.
Integer math or floating point math makes no difference.  Your format mask prevents the display of any decimal places.
Agreed BUT one would see the integer part (0.9*10 = 9).  Currently that is apparently zero after the multiplication.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.