我正在尝试在 Python 脚本中执行 SQL 存储过程,但遇到语法问题。我尝试了我找到的各种示例的组合,但似乎没有一个起作用。这是我尝试过的:county = 100200confirmed = 123456death = 12labTestCount = 0 #Example1conn.execute('{CALL [spInsertCOVIDData](@County,@Confirmed,@Death,@LabTestCount)}', ('county', 'confirmed', 'death', 'labTestCount'))#Example2query = "EXEC [spInsertCOVIDData] (@County,@Confirmed,@Death,@LabTestCount)", (county, confirmed, death, labTestCount)conn.execute(query)#Example3query = "EXEC [spInsertCOVIDData] @County=?, @Confirmed=?, @Death=?, @LabTestCount=?",(county, confirmed, death, labTestCount)conn.execute(query)#Example4query = "EXEC [spInsertCOVIDData] @County='county', @Confirmed='confirmed', @Death='death', @LabTestCount='labTestCount'"conn.execute(query)我从以下位置得到了各种错误的混合:('The SQL contains 0 parameter markers, but 4 parameters were supplied', 'HY000')或者The first argument to execute must be a string or unicode query.
1 回答
慕哥6287543
TA贡献1831条经验 获得超10个赞
您可以尝试在语句中使用参数?作为占位符并传递每个参数的实际值:
county = 100200
confirmed = 123456
death = 12
labTestCount = 0
query = "EXEC [spInsertCOVIDData] @County=?, @Confirmed=?, @Death=?, @LabTestCount=?"
conn.execute(query, (county, confirmed, death, labTestCount))
添加回答
举报
0/150
提交
取消