python - 使用python和cx_oracle读写Clob数据

标签 python json oracle clob cx-oracle

我正在尝试从测试数据库读取 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/

相关文章:

python - 引发错误类与类实例的优缺点是什么

c++ - 使用 Boost Variants 在 C++ 中表示 JSON 数据

Python3 无法将字符串转换为 dict 或 json

sql - Oracle RAC 和序列

python - Python意外退出后如何让程序再次运行?

Python:对于大型列表来说,有什么比没有更快的东西?

javascript - 返回多维数组

sql - 在Oracle SQL表中更新日期

node.js - 如何解决 "Unable to resolve some modules oracledb"?

python - Py2exe - 无法使用 Windows 7 计算机运行在 Windows 10 上创建的 .exe