python-3.x - Oracle ORA-01036 存在问题:非法变量名/编号
问题描述
我需要将以下值替换为选择查询。但我收到了下面提到的错误
def addSoil(self):
name = self.ent_name.get()
texture = self.ent_texture.get()
colour = self.ent_colour.get()
capacity = self.ent_capacity.get()
equation = self.ent_equation.get()
try:
con = cx_Oracle.connect('hr/hr@192.168.56.1/xepdb1')
cursor = con.cursor()
cursor.execute('INSERT INTO soildata (soil_name, soil_text, soil_colour, soil_waterhold, soil_chemicalequ) '
'VALUES(%s,%s,%s,%s,%s)', (name,texture,colour,capacity,equation))
con.commit()
except cx_Oracle.DatabaseError as e:
print("There is a problem with Oracle", e)
finally:
if cursor:
cursor.close()
if con:
con.close()
解决方案
您使用了错误的占位符语法。你需要做这样的事情:
cursor.execute('INSERT INTO soildata (soil_name, soil_text, soil_colour, soil_waterhold, soil_chemicalequ) '
'VALUES(:1,:2,:3,:4,:5)', (name,texture,colour,capacity,equation))
您也可以查看文档以获得进一步的帮助。
推荐阅读
- selenium - BrowserStack - IE11 上的错误发送键
- c# - 所选 excel WorkSheet 的 m_ObjectToDataMap 为“null”
- c++ - 如果没有逻辑方法来定义比较运算符,如何使用自定义类作为 std::map 的键?
- c# - ASP.NET Core 2.2 锁定未激活
- angular - 结构指令获取子指令
- javascript - 如何使用javascript从另一个文件中设置元素的innerHTML?
- c# - 将 IN 子句中的多个数字作为参数传递给 Oracle 查询时出现无效数字异常
- angular - gulp 错误:错误:找不到模块'@microsoft/sp-build-web'
- python - 如何选择 QTableWidget 的多个单元格?
- html - 为什么我的
出现在同一行的段落?