从数据库直接读取小于1GB的CLOBs and BLOBs的格式作为字符串,这比数据流方式更快。 这里用到了connection.outputtypehandler: def OutputTypeHandler ( cursor , name , defaultType , size , precisio
从数据库直接读取小于1GB的CLOBs and BLOBs的格式作为字符串,这比数据流方式更快。
这里用到了connection.outputtypehandler:
if defaultType == cx_Oracle.DB_TYPE_CLOB:
return cursor.var(cx_Oracle.DB_TYPE_LONG, arraysize=cursor.arraysize)
if defaultType == cx_Oracle.DB_TYPE_BLOB:
return cursor.var(cx_Oracle.DB_TYPE_LONG_RAW, arraysize=cursor.arraysize)
idVal = 1
textData = "The quick brown fox jumps over the lazy dog"
bytesData = b"Some binary data"
cursor.execute("insert into lob_tbl (id, c, b) values (:1, :2, :3)",
[idVal, textData, bytesData])
connection.outputtypehandler = OutputTypeHandler
cursor.execute("select c, b from lob_tbl where id = :1", [idVal])
clobData, blobData = cursor.fetchone()
print("CLOB length:", len(clobData))
print("CLOB data:", clobData)
print("BLOB length:", len(blobData))
print("BLOB data:", blobData)
参考:https://cx-oracle.readthedocs.io/en/latest/user_guide/lob_data.html#lobdata