【发布时间】:2020-10-22 22:09:07
【问题描述】:
data=[]
dataToInsert = [ ]
for index, row in df.iterrows():
contentid = row['CONTENTID']
Objectsummary = row['OBJECT_SUMMARY']
Title=row['TITLE']
if Title is None:
Title = ""
if Objectsummary is None:
Objectsummary = ""
allSummeries =Title + ' ' + Objectsummary
lists=function_togetNounsAndVerbs(allSummeries)
verbList =lists[0]
nounList =lists[1]
NounSet = set(nounList)
VerbSet = set(verbList)
verbs = " "
verbs=verbs.join(VerbSet)
nouns=" "
nouns=nouns.join(NounSet)
verbs=re.sub(r" ", ", ", verbs)
nouns=re.sub(r" ", ", ", nouns)
# Here we are going to create the data sdet to be updated in database table in batch form.
data.append(nouns)
data.append(verbs)
data.append('PROCESSED')
data.append(contentid)
dataToInsert.append([data[0], data[1], data[2], data[3]])
print("ALL DATA TO BE UPDATED IN TABLE IS :---> ",dataToInsert)
statement = """UPDATE test_batch_update_python SET NOUNS = ?, Verbs = ? where CONTENTID = ?"""
a = cursor.executemany(statement, dataToInsert)
connection.commit()
在上面的代码中 function_togetNounsAndVerbs(allSummeries) 这个函数将返回列表。 我收到以下异常:
**a = cursor.executemany(statement, dataToInsert)
cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number**
请帮我解决这个问题。 或者我还有什么其他方法可以做到这一点。最初,我曾经使用 cursor.execute() 一次更新单行,但这非常耗时。为了尽量减少我使用批量上传的时间(即 cursor.executemany() )
【问题讨论】:
-
您的查询中有 3 个占位符:
UPDATE test_batch_update_python SET NOUNS = ?, Verbs = ? where CONTENTID = ?,但您将 4 个项目附加到data。要么您错过了查询中的一列,要么您需要删除'PROCESSED'。 -
使用 Oracle,您需要使用 ":name" 而不是 "?"用于 SQL 语句中的绑定占位符。检查 cx_Oracle 文档 Batch Statement Execution and Bulk Loading 和 Using Bind Variables。
标签: python oracle executemany