Read Clob from JayBeDeAPI Query

1.7k views Asked by At

I'm using python's jaybedeapi to connect to an Oracle database. Everything seems to be working fine, except when I encounter fields with oracle.sql.clob data:

Connection & query:

conn = jaydebeapi.connect('oracle.jdbc.OracleDriver','jdbc:oracle:thin:user/pass@host:port:db')

cur = conn.cursor()

cur.execute("select * from table")

data = cur.fetchmany(size=10)

print data[0][1] 

Returning:

<jpype._jclass.oracle.sql.CLOB at 0x5fe83d543c92>

How can I print the value in these fields?

EDIT:

I prefer not to explicitly call out each field DBMS_LOB.substr(field,3000) in the select statement (which works). If possible, I'd rather have a solution directly in python.

1

There are 1 answers

0
RunDeep On

This just worked for me:

db_result = data[0][1]
print db_result.getSubString(1, db_result.length())

I'm using jaydebeapi version 0.2.0 and jpype 0.5.7, Python 2.7.10/32 on Win 7/64. Found the solution here: http://almostflan.com/t/embedclob/ though I didn't have the autocommit issue he did.