Search code examples
python-2.7clobcx-oracle

facing error: ProgrammingError: LOB variable no longer valid after subsequent fetch


I fetched records from database to mylist and then want to use .decode function on each of the list elements, but that gives me AttributeError: 'cx_Oracle.LOB' object has no attribute 'decode', so I am trying to convert elements into string before using .decode function but I am facing below error for some elements in list:

mylist[rr] = [str(x) for x in mylist[rr]]

ProgrammingError: LOB variable no longer valid after subsequent fetch


Solution

  • You have a few options available here:

    (1) upgrade to cx_Oracle 6.x which eliminated this error

    (2) use an iterator to process the cursor instead of cursor.fetchall()

    (3) if the CLOBs being returned are reasonably small use an output type handler to convert the LOB to a string which improves performance as well due to reduced round-trips to the database (see https://github.com/oracle/python-cx_Oracle/blob/master/samples/ReturnLobsAsStrings.py)

    Hopefully one of those options will work for you!