Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert cx_Oracle.LOB data to string in python

Tags:

python

I have this list:

['ThisText', <cx_Oracle.LOB object at 0x02FDC080>]

Lst[1] content :

This is a string but as clob

Im populating the list from this query result as such :

import cx_Oracle

dsn_tns = cx_Oracle.makedsn('mario.connex.ro', '1529', service_name='EAIUAT')
conn = cx_Oracle.connect(user=r'LOGGING_DB05', password='passw0rd', dsn=dsn_tns)

c = conn.cursor()
c.execute("select column1, column2 from DB_Table where column3 = '1234'")

lst = []


for i in c:
    for j in i:
        lst.append(j)

table structure is :

Column1 = varchar
Column2 = clob
Column3 = varchar

I want to convert the clob value from lst[1] to string

str = ''.join(lst[1])

Error received :

TypeError: can only join an iterable

Printed the lst[1] type :

print(type(lst[1]))
<class 'cx_Oracle.LOB'>

Is there a way to convert the cx_Oracle.LOB value to string?

like image 233
MGA Avatar asked May 14 '20 06:05

MGA


People also ask

What is cx_Oracle lob?

There are four types of LOB (large object): BLOB - Binary Large Object, used for storing binary data. cx_Oracle uses the type cx_Oracle. DB_TYPE_BLOB . CLOB - Character Large Object, used for string strings in the database character set format.

What is Python cx_Oracle?

cx_Oracle is a Python extension module that enables access to Oracle Database. It conforms to the Python database API 2.0 specification with a considerable number of additions and a couple of exclusions.


1 Answers

Solved : using cx.oracle.LOB.read() method to retrive LOB data.

str = ''.join(lst[3].read())
like image 117
MGA Avatar answered Sep 27 '22 23:09

MGA