在python中更新查询执行

时间:2016-10-07 07:09:10

标签: python sql oracle

我正在sql开发人员执行此查询,它工作正常

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

但是当我通过python代码执行此操作时

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

我收到错误

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

请让我知道我在做错的地方。

2 个答案:

答案 0 :(得分:0)

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

var myObjects = [
{ name: "Object1", shape: "circle", color: "red" },
{ name: "Object2", shape: "square", color: "orange" },
{ name: "Object3", shape: "triangle", color: "yellow" },
{ name: "Object4", shape: "circle", color: "green" },
{ name: "Object5", shape: "sphere", color: "blue" },
{ name: "Object6", shape: "hexagon", color: "indigo" },
{ name: "Object7", shape: "square", color: "violet" }
];

var myRedObjects = $filter('filter')(myObjects, { color: "red" });

myRedObjects = myRedObjects[0].name= "RedObjectNewName";

答案 1 :(得分:0)

我有更好的方法

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

它完成了!谢谢!