【发布时间】:2015-01-10 02:08:33
【问题描述】:
在我的 Python 代码中,当我要求用户向 SELECT 输入字符串时,它可以工作,但是当我使用相同的输入尝试 UPDATE 时,我无法执行
这是我连接成功后的代码
curs = connection.cursor()
str_input1 = str(input("Input : "))
str_input2 = str(input("Input : "))
statement = "UPDATE table SET variable1 = "+str_input1+" WHERE name = "+str_input2
curs.execute(statement)
connection.commit
理论上,下面的代码应该可以工作并更新变量,但是我在 curs.execute(statement) 行得到错误
cx_Oracle.DatabaseError: ORA-00904: John: invalid identifier
John 是 where 子句的 str_input2
也许是它的格式给了我一个错误,但我不太确定。
谁能指出我的代码有什么问题?
【问题讨论】:
标签: python sql-update cx-oracle