Avatar of PearlJamFanatic
PearlJamFanatic

asked on 

opencsv does not handle DOUBLE_BINARY

I used the opencsv (http://opencsv.sourceforge.net/) library to export resultsets to csv file. I use the writeAll method defined within the library. But somehow BINARY_DOUBLE fields (Oracle) of the table are not getting exported properly. the field contains 0.0 in the table but it is exported as '' to csv. Please help.
JavaOracle Database

Avatar of undefined
Last Comment
PearlJamFanatic
Avatar of Mick Barry
Mick Barry
Flag of Australia image

thats a proprietary type so opencsv would not know how to display it
Avatar of Mick Barry
Mick Barry
Flag of Australia image

you'll need to write the csv 'manually' (still using opencsv) to handle that column type
ASKER CERTIFIED SOLUTION
Avatar of mrjoltcola
mrjoltcola
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of for_yan
for_yan
Flag of United States of America image



You can probably use to_number(...) in the query to convert it to the number
http://psoug.org/snippet/TO_NUMBER-_650.htm

SOLUTION
Avatar of mrjoltcola
mrjoltcola
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Mick Barry
Mick Barry
Flag of Australia image

mrjoltcola> As a workaround, try casting that column in your SQL to a NUMBER(38)

good idea, NUMBER will work

Avatar of for_yan
for_yan
Flag of United States of America image

BINARY_DOUBLE was introduced only in Oracle10
Just check that you are using the latest jdbc driver
It probably would have complained, but still good to check
Avatar of PearlJamFanatic
PearlJamFanatic

ASKER

select ..., cast(bindblcol as NUMBER(32)),  loses the decimal points. Is there a way to keep upto 10 decimal points.
Avatar of Mick Barry
Mick Barry
Flag of Australia image

see mrjoltcola's correction
Avatar of for_yan
for_yan
Flag of United States of America image

select to_char(column, '999999.999999')  -- works for normal numbers - don't knwo if it owuld work
for bbinary dounl;e
Avatar of PearlJamFanatic

ASKER

And if there is a null in the data will the cast statement raise an error?
Avatar of for_yan
for_yan
Flag of United States of America image

You can use decode function to address it:
Decode (columnn, null, 0, cast(..))
Will return the required number
Avatar of Mick Barry
Mick Barry
Flag of Australia image

try:

CAST(NVL(bindblcol, 0) as NUMBER(38,10))
Avatar of PearlJamFanatic

ASKER

I am doing this in sybase
cast(round(tax_wthld_rte,10) as Numeric(38,10))

This convert 0 to 0.0000000000
But I want that it should be just 0 after casting.

In oracle
cast(TAX_WTHLD_RTE as NUMBER(38,17))
returns 0 after casting wherever there is 0

Also need the a way to handle error on cast in sybase if the field had null
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo