Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Import BLOB form ORACLE

28 views
Skip to first unread message

Bozena Lopuch

unread,
Jul 27, 2009, 5:56:03 AM7/27/09
to
I need to import BLOB form ORACLE database.
I use
curs = exec(conn, [ 'select obraz from CALE_OBRAZY WHERE NAZWA_PLIKU = ' '''' nazwa_pl '''' ] );
cr= fetch(curs);
I've got answer only: [1x1 oracle.sql.BLOB]
without any data.
Please help!!!

Andy

unread,
Jul 27, 2009, 9:36:02 AM7/27/09
to
"Bozena Lopuch" <boz...@wit.edu.pl> wrote in message <h4jtjj$chj$1...@fred.mathworks.com>...

The exec command returns a cursor object, which is a MATLAB structure with several fields that provides a link to the result returned from your query and several pieces of information about it. One of the fields of curs is the 'Data' field, which is set to 'No Data' when exec is first called. The fetch command puts data into the Data field. So to get the data out, you do something like this:

% begin code
curs=exec(conn,sqlquery);
curs=fetch(curs);
blob=curs.Data;
% end code

Note: Use curs=fetch(curs) instead of cr=fetch(curs). This doesn't overwrite the cursor object. It stores the fetched data in the data field. The way you have written your code, you'll have extra cursor objects lying around that you'll have to close.

Bozena Lopuch

unread,
Jul 30, 2009, 6:30:20 AM7/30/09
to
"Andy " <theori...@gmail.com> wrote in message <h4kag2$mv0$1...@fred.mathworks.com>...

Unfortunately, your method doesn't work. I still get answer
[1x1 oracle.sql.BLOB]
Thank you for you trying.

Cornelius

unread,
Sep 29, 2009, 8:49:02 AM9/29/09
to
"Bozena Lopuch" <boz...@wit.edu.pl> wrote in message <h4jtjj$chj$1...@fred.mathworks.com>...


I have got the same problem. Even when I exactly copied the blob example from the matlab help (in the help files they say, that the return format is [21626x1 int8].
Did you find any solution.

Asmita

unread,
Sep 23, 2011, 5:02:29 PM9/23/11
to
"Cornelius " <c.br...@hff-potsdam.de> wrote in message <h9svnu$ht0$1...@fred.mathworks.com>...
Hi

Here is how you can convert Oracle BLOBs back to images:

%Skipping the connecting and fetching parts here – assuming curs.Data contains the BLOB object

%In case of JDBC or when you get 'Oracle.sql.BLOB', here is how you can get the byte array:

image = curs.Data;
myData = getBytes(image, 1, length(image));

%In case of ODBC or when you have the byte array, just take it in the variable 'image'

image = curs.Data;

%Execute the following part in MATLAB to store the byte array to a file and then read the file as an image

import java.io.*

f= File('myImage')

os = BufferedOutputStream(FileOutputStream(f))

write(os, myData, 0, length(myData))

imshow('myImage')


Thanks,
Asmita
0 new messages