opencsv does not handle DOUBLE_BINARY

PearlJamFanatic
PearlJamFanatic used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mick BarryJava Developer
Top Expert 2010

Commented:
thats a proprietary type so opencsv would not know how to display it
Mick BarryJava Developer
Top Expert 2010

Commented:
you'll need to write the csv 'manually' (still using opencsv) to handle that column type
Top Expert 2009
Commented:
As a workaround, try casting that column in your SQL to a NUMBER(38)

select ..., cast(bindblcol as NUMBER(32)),
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Awarded 2011
Awarded 2011

Commented:


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

Top Expert 2009
Commented:
Correction, cast it to something like NUMBER(38,8)
Mick BarryJava Developer
Top Expert 2010

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

good idea, NUMBER will work

Awarded 2011
Awarded 2011

Commented:
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

Author

Commented:
select ..., cast(bindblcol as NUMBER(32)),  loses the decimal points. Is there a way to keep upto 10 decimal points.
Mick BarryJava Developer
Top Expert 2010

Commented:
see mrjoltcola's correction
Awarded 2011
Awarded 2011

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

Author

Commented:
And if there is a null in the data will the cast statement raise an error?
Awarded 2011
Awarded 2011

Commented:
You can use decode function to address it:
Decode (columnn, null, 0, cast(..))
Will return the required number
Mick BarryJava Developer
Top Expert 2010

Commented:
try:

CAST(NVL(bindblcol, 0) as NUMBER(38,10))

Author

Commented:
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial