首页 > 解决方案 > 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()

标签: python-3.xtkinterpycharmcx-oracleoracle18c

解决方案


您使用了错误的占位符语法。你需要做这样的事情:

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))

您也可以查看文档以获得进一步的帮助。


推荐阅读