【发布时间】:2020-07-22 07:08:24
【问题描述】:
我刚开始学习 python,我的要求是基于 Oracle 表中的一列,我使用字典键对值更新其他列。我的字典看起来像这样
{'United States': 'American', 'France': 'European', 'Great Britain': 'European'}
所以当国家列是美国时,描述列应该更新为美国,在我的数据库连接之后,这是我的代码
query = "select country from details_table "
cursor.execute(query)
returnrows = cursor.fetchone()
while returnrows is not None:
pickedvalue=returnrows[0]
mainvalue=file_dictionary[pickedvalue]
updatequery = "update details_table set description='%s' where country='%s'"
cursor.execute(updatequery %(mainvalue,pickedvalue))
returnrows = cursor.fetchone()
当我执行此操作时,我得到错误“不是查询”,所以我尝试更改引号,每次都会得到不同的错误
updatequery = "update details_table set description=%s where country=%s"
updatequery = "update details_table set description='%s' where country=%s"
对于以上两个查询,我得到 ORA-00933: SQL command not properly end
updatequery = "update details_table set description=%s where country='%s'"
为此我得到了 ORA-00904: "AMERICAN": invalid identifier
有人能告诉我哪个是正确的查询吗?我什至像下面这样尝试但没有运气
updatequery="update details_table set description={} where country='{}'"
sql=updatequery.format(main_value,pickedvalue)
cursor.execute(sql)
【问题讨论】:
标签: python-3.x oracle dictionary cx-oracle