I'm trying to retrieve the contents of a BLOB column from an Oracle Database using mybatis. There is a table 'Demo' that contains a column 'binfile' of type BLOB. I would like to select the BLOB column and display it as a byte array/raw binary data. I'm using a Oracle thin JDBC driver.
The query in the mybatis mapper looks like this:
<mapper namespace="Oracle" >
...
<select id="SelectBinary" resultType="hashmap">
SELECT binfile from mpdemo.Demo
</select>
</mapper>
If I do this, the result I get looks like this:
BINFILE: "oracle.sql.BLOB@5d67eb18"
If I do this:
<select id="SelectBinaryDup" resultType="hashmap">
SELECT utl_raw.cast_to_varchar2(dbms_lob.substr(binfile)) from mpdemo.Demo
</select>
I obviously get an error saying that the raw variable saying 'PL/SQL: numeric or value error: raw variable length too long' as the image is well over 100 kB, since a VARCHAR2 variable in SQL can support only 2000 bytes.
Is there a solution to this?
I thought of writing a stored proc that reads the BLOB column block by block and writes the output to a file. But that file will be saved on the database server and I can't retrieve that.