How to use Database Toolbox to write double data type to Oracle database BINARY_DOUBLE data type?

1 view (last 30 days)
My first trial use of MatLab's Database Toolbox, and I'm getting this error:
>> datainsert(conn, 'test_table', {'col1'}, {my_double_variable}) Error using database/datainsert (line 129) Unable to insert element in row 1 column 1, 2.5198. java.lang.Double cannot be cast to oracle.sql.BINARY_DOUBLE
>> whos
Name Size Bytes Class
ans 1x1 1 logical
conn 1x1 2322 database
my_double_variable 1x1 8 double
I need to use Oracle's binary_double data type because it maps to IEEE 754 floating-point representation, so it's a perfect match for the data in Matlab.
I've written Java programs that write and read java's double data type to Oracle's binary_double data type using JDBC. Since Matlab also uses Oracle's JDBC driver to communicate with the database, I don't understand the limitation here.
Can Matlab's Database Toolbox map Matlab double data type to Oracles' binary_double, both based on IEEE 754? If not, how does one ensure the data maps exactly?
UPDATE 1:
I found using insert or fastinsert doesn't produce any errors, but in both cases the double value in Matlab is converted to Number Oracle data type then converted by Oracle to binary_double. The downside is the Number format can only store a much much smaller range of values, and there will be some conversion errors introduced. I observed this by saving a number smaller than 1e-130, which is the limit of Number data type. For example, if you try to write 1e-131 into a database column of binary_double data type you'll get an error for fastinsert and simply 0 for insert. True double (and binary_double) reaches down to 2e-308.
UPDATE 2:
Feedback from Database Toolbox support at MathWorks says Oracle binary_float and binary_double data types are not supported.
Not sure what workaround is best. Perhaps I should store the mantissa in one column and the exponent in another column (seems an ugly hack). Or, I could store the exponential number as a VARCHAR2 then convert to double upon retrieval.
Anyone ever run into this before?

Answers (1)

Malcolm Lidierth
Malcolm Lidierth on 24 Aug 2012
java.lang.Double is a Java 'boxed' type. Could use the IEEE binary value in your code?. That is returned by the doubleValue() method in the Double class.
datainsert(conn, 'test_table', {'col1'}, {my_double_variable.doubleValue()})
  2 Comments
Malcolm Lidierth
Malcolm Lidierth on 24 Aug 2012
GG Yes. The whos output shows that my_double_variable is double, not Double anyway. Why use {}? MATLAB numeric matrices are supported directly according to the docs.

Sign in to comment.

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by