我正在尝试解析多个 CSV 并使用 cx_Oracle 将它们的数据插入到表中。我使用execute插入表没有问题,但是当我尝试使用executemany执行相同的过程时出现错误。我使用执行的代码是
with open(key,'r') as file:
for line in file:
data = data.split(",")
query = "INSERT INTO " + tables[key] + " VALUES ("
for col in range(len(data)):
query += ":" + str(col) + ","
query = query[:-1] + ")"
cursor.execute(query, data)
但是当我用
with open(key,'r') as file:
list = []
for line in file:
data = data.split(",")
list.append(data)
if len(list) > 0:
query = "INSERT INTO " + tables[key] + " VALUES ("
for col in range(len(data)):
query += ":" + str(col) + ","
query = query[:-1] + ")"
cursor.prepare(query)
cursor.executemany(None,list)
尝试插入具有 CLOB 列且数据超过 4000 字节的表时,出现“ValueError:字符串数据太大”。当表没有 CLOB 列时,Executemany 效果很好。有没有办法告诉 cx_Oracle 在执行时将适当的列视为 CLOB?