2

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.

datasci
  • 1,019
  • 2
  • 12
  • 29
  • Can you please try [this feature branch](https://github.com/baztian/jaydebeapi/tree/feature/advanced-datatypes)? – bastian Jun 11 '15 at 16:19
  • I've tried it myself and I have to admin that it doesn't work currently. But please see [this comment to a jaydebeapi issue](https://github.com/baztian/jaydebeapi/issues/6#issuecomment-112553645) which might help. – bastian Jun 16 '15 at 20:13
  • Yea, it didn't work for me. – datasci Jun 18 '15 at 14:31

1 Answers1

4

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.

RunDeep
  • 186
  • 1
  • 10