使用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 = r'INSERT INTO test (id, name, salesrep) VALUES (?, ?, ?)'