与execute一起使用时,INSERT在cx_oracle中不起作用。如何使其运作?

| 我是cx_oracle的新手。我已经建立了连接,并且能够使用execute创建和删除表。 我失败的地方是当我尝试在执行中使用\“ INSERT INTO ... \”时。它不显示任何错误,但也不存储任何值(我通过检查输入是否已使用shell中的sqlplus进行确认了)。我使用的代码是:
table_name = \"T1\"
column = \"D\"
insert_value = \"test value\"

sqlcode = \"INSERT INTO \"+table_name+\" (\"+column+\") VALUES (\'\"+insert_value+\"\')\"
cursor.execute(sqlcode)
请帮助我,任何帮助将不胜感激。 提前致谢。 Ĵ     
已邀请:
当Cursor中的方法没有提交,连接具有此方法时,ѭ1如何工作,因此应为:
    connection.commit()
使用
cursor.commit()
返回:
AttributeError: \'cx_Oracle.Cursor\' object has no attribute \'commit\'
    
奇怪的是您没有得到该代码的错误;当然,除非您(很难)调用Cursor对象
connect
。 在所有代码之前,您需要在某处具有这样的内容:
conn = cx_Oracle.connect(usr, pwd, url)
cursor = conn.cursor()
然后继续将
connect.execute(sqlcode)
替换为
cursor.execute(sqlcode)
。     

要回复问题请先登录注册