我试图在python中执行以下代码,但结果是 syntax error near '(' 的错误 executemany(..) 。当我从 sql 然后写 %s 它还导致以下错误: there are more placeholders thant the variables 有人知道我怎么修吗?
syntax error near '('
executemany(..)
sql
%s
there are more placeholders thant the variables
upInfo ={"aa": "aaa","bb": "bbb","cc": "ccc"} sql = 'UPDATE table SET a= %(aa)s WHERE b= %(bb)s and c= %(cc)s' con = pymssql.connect(...) con.autocommit(True) cur = con.cursor() cur.executemany(sql, upInfo)
因为这是 executemany() ,应该是字典列表:
executemany()
upInfo = [{"aa": "aaa", "bb": "bbb", "cc": "ccc"}]
或者,使用正则表达式 execute() :
execute()
cur.execute(sql, upInfo)