我正在尝试从测试数据库读取 Clob 数据并将其插入开发数据库。我能够做到这一点,但性能很差。 对于 100K 行,需要 8 到 12 小时,并且从我的本地计算机运行它。 我想知道我的方法是否正确或者是否有更好的方法。 下面是我连接后的代码:
for row in rows.fetchall()
x = []
data = row.read
json_data = json.loads(data)
x.append(json_data)
我就是这样做的。只是想知道是否有更好的方法。 堆栈:Python、OracleDB、cx_oracle、json 谢谢
最佳答案
来自cx_Oracle sample以下代码是您要使用的代码。这应该会显着提高性能!
def OutputTypeHandler(cursor, name, defaultType, size, precision, scale):
if defaultType == cx_Oracle.CLOB:
return cursor.var(cx_Oracle.LONG_STRING, arraysize = cursor.arraysize)
elif defaultType == cx_Oracle.BLOB:
return cursor.var(cx_Oracle.LONG_BINARY, arraysize = cursor.arraysize)
conn = cx_Oracle.Connection("user/pw@dsn")
conn.outputtypehandler = OutputTypeHandler
cursor = conn.cursor()
cursor.execute("""
select CLOBColumn
from SomeTable""")
json_data = [json.loads(s) for s, in cursor]
关于python - 使用python和cx_oracle读写Clob数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49288724/