Equalizer
Equalizer

Reputation: 47

How to retrieve a BLOB record from table as bytes using cx_Oracle

I have a binary file which I have inserted into a blob column in a table. Now, I want to retrieve this file as a bytes object. But I am getting it as a tuple.

What I have tried so far:
I am trying to retrieve the file from this blob column with the query below: as explained in the cx_Oracle documentation https://cx-oracle.readthedocs.io/en/latest/user_guide/lob_data.html#fetching-lobs-as-strings-and-bytes

def output_type_handler(cursor, name, default_type, size, precision, scale):
    if default_type == cx_Oracle.DB_TYPE_BLOB:
        return cursor.var(cx_Oracle.DB_TYPE_LONG_RAW, arraysize=cursor.arraysize)

connection.outputtypehandler = output_type_handler
cur.execute('''select blobcol from table''')
data = cur.fetchone()

Now, if I do a type(data), I am getting it as a tuple and not as bytes.

How do I retrieve the blob object as bytes and not a tuple?

Upvotes: 0

Views: 369

Answers (1)

Equalizer
Equalizer

Reputation: 47

The byte object can be accessed within the tuple as data[0]

Upvotes: 1

Related Questions