How do I read cx_Oracle.LOB data in Python?

前端 未结 4 607
庸人自扰
庸人自扰 2020-12-31 04:06

I have this code:

    dsn = cx_Oracle.makedsn(hostname, port, sid)
    orcl = cx_Oracle.connect(username + \'/\' + password + \'@\' + dsn)
    curs = orcl.cu         


        
4条回答
  •  -上瘾入骨i
    2020-12-31 04:32

    I've found out that this happens in case when connection to Oracle is closed before the cx_Oracle.LOB.read() method is used.

    orcl = cx_Oracle.connect(usrpass+'@'+dbase)
    c = orcl.cursor()
    c.execute(sq)
    dane =  c.fetchall()
    
    orcl.close() # before reading LOB to str
    
    wkt = dane[0][0].read()
    

    And I get: DatabaseError: Invalid handle!
    But the following code works:

    orcl = cx_Oracle.connect(usrpass+'@'+dbase)
    c = orcl.cursor()
    c.execute(sq)
    dane =  c.fetchall()
    
    wkt = dane[0][0].read()
    
    orcl.close() # after reading LOB to str
    

提交回复
热议问题