首页 > 数据库 >Python错误:pyodbc executemany 报错:The SQL contains 0 parameter markers, but 3 parameters were supplied‘

Python错误:pyodbc executemany 报错:The SQL contains 0 parameter markers, but 3 parameters were supplied‘

时间:2022-10-08 13:11:34浏览次数:63  
标签:executemany parameters supplied 报错 HY000 sql pyodbc

问题描述:

使用executemany插入多条记录时:

sql = r'INSERT INTO test (id, name, salesrep) VALUES (%s, %s, %s)'
vals = [('1', 'John Smith', 'John Doe'),
('2', 'Jane Doe', 'Joe Dog'),
('3', 'Mike T.', 'Sarah H.')]
cursor.executemany(sql, vals)

 报以下错误:标记符与值不匹配!

cursor.executemany(sql, vals)
pyodbc.ProgrammingError: ('The SQL contains 0 parameter markers, but 3 parameters were supplied', 'HY000')

 

解决办法:

原因分析:sql未能识别参数。

解决办法:将占位符%换成?

sql = r'INSERT INTO test (id, name, salesrep) VALUES (?, ?, ?)'

 

标签:executemany,parameters,supplied,报错,HY000,sql,pyodbc
From: https://www.cnblogs.com/zhengxianfa/p/16768622.html

相关文章