简体   繁体   English

更新python中的查询执行

[英]update query execution in python

I am executing this query on sql developer and it is working fine 我正在sql Developer上执行此查询,并且工作正常

update TABLE_X set COL_SID='19' where ID='1';

But when I am doing this via python code 但是当我通过python代码执行此操作时

cur=conn.cursor()
updt_query='update TABLE_X set COL_SID=? where ID=?'
cur.execute(updt_query,('19','1'))
cur.close()

I am getting error 我遇到错误

cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number

Please let me know where I am doing the mistake. 请让我知道我在哪里做错了。

可能是ID是数字而不是字符串,所以您应该使用

 cur.execute(updt_query,(19,1))

I got a better way 我有更好的办法

cur=conn.cursor()
updt_query='update TABLE_X set COL_SID=:cs where ID=:id'
cur.execute(updt_query,{cs:'19',id:'1'})
cur.close()

Its done ! 完成 ! Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM