Skip to content Skip to sidebar Skip to footer

Blob Data From Oracle To Text File Using Python

I have been trying to get the blob data from oracle into a text file using Python. I couldn't find the answer on any of the other links. Below is my code : sql_string = '''select

Solution 1:

You have to use the cx_oracle.LOB.read() method to get the content of the LOB object:

f.write(row[2].read())

Solution 2:

Implemented what @blhsing suggested and it worked out perfectly

    for row in cur:
        filename = path +  "notes_" + str(row[0]) + "_" + str(row[1]) + ".txt"print(row[2].read())
        f = open(filename, "wb")
        f.write(row[2].read())
        f.close()        

Solution 3:

If your LOBs are small enough to fit in memory you'll get better performance if you fetch BLOBs as LONG_BINARY (and use LONG_STRING for CLOBs):

def OutputTypeHandler(cursor, name, defaultType, size, precision, scale):
    ifdefaultType== cx_Oracle.CLOB:
        return cursor.var(cx_Oracle.LONG_STRING, arraysize = cursor.arraysize)
    ifdefaultType== cx_Oracle.BLOB:
        return cursor.var(cx_Oracle.LONG_BINARY, arraysize = cursor.arraysize)

See the cx_Oracle example at https://github.com/oracle/python-cx_Oracle/blob/master/samples/ReturnLobsAsStrings.py

Post a Comment for "Blob Data From Oracle To Text File Using Python"