【问题标题】:There is a problem with Oracle ORA-01036: illegal variable name/numberOracle ORA-01036 存在问题:非法变量名/编号
【发布时间】:2020-06-30 09:05:51
【问题描述】:

我需要将以下值替换为选择查询。但我得到了下面提到的错误

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

【问题讨论】:

  • 您的self.ent_*. 中存储了哪些类型?检查soil_name, soil_text, soil_colour, soil_waterhold, soil_chemicalequ的名称
  • 尝试将五个占位符 %s 更改为 :1,:2,:3,:4,:5

标签: python-3.x tkinter pycharm cx-oracle oracle18c


【解决方案1】:

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

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

您也可以查看documentation 以获得更多帮助。

【讨论】:

    猜你喜欢
    • 2018-10-16
    • 1970-01-01
    • 1970-01-01
    • 2013-01-06
    • 2018-05-21
    • 2011-10-05
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    相关资源
    最近更新 更多