当我尝试连续更新多个值时,SQL Python 抛出错误

问题描述 投票:0回答:1
c.execute('update MainDB set name=%s, set opportunity=%s, set value=%s, set stage=%s, set startdate=%s, set lastupdate=%s where rowid = %s',(name,opportunity,value,Stage,startdate,date,rowid))

我有一个包含列的表 MainDB

name (text), 
opportunity (text), 
value (int), 
stage (int), 
startdate (text) 
lastupdate (text) 

使用这行代码,我想更新该行中的所有值,但出现错误

您的 SQL 语法有错误

我无法在网上找到任何其他有效的语法。我的语法有什么问题吗?

python mysql mysql-python
1个回答
3
投票

在 UPDATE 语句中,您只需使用

SET
关键字一次。接下来是逗号分隔的作业列表。

错误:

update MainDB set name=%s, set opportunity=%s, set value=%s, set stage=%s, 
  set startdate=%s, set lastupdate=%s where ...

正确:

update MainDB set name=%s, opportunity=%s, value=%s, stage=%s,
  startdate=%s, lastupdate=%s where ...

这在语法参考和更新语法文档中显示的示例中很清楚。

© www.soinside.com 2019 - 2024. All rights reserved.