首页 文章

sqlite3.ProgrammingError:提供的绑定数量不正确 . 当前语句使用0,并且提供了9

提问于
浏览
0

我试图将 input 变量用于 SELECT 语句但是得到以下错误 .

这是我的代码:

sheetname=input("Enter the name of the SEO Analysis sheet:")
cur=conn.execute("select * from seo_info where url like '%?%'",sheetname,)
print(cur.fetchall())

这是一个错误:

File "E:/Python/SEO_Project2.py", line 40, in <module>
cur=conn.execute("select * from seo_info where url like '%?%'",sheetname,)
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are 9 supplied.

这是another question,它解决了问题的一部分,但它仍然给我错误 .
也许我在代码中遗漏了一些东西?

2 回答

  • 1

    我做的 !

    cur=conn.execute("select * from seo_info where url like (?)",['%'+sheetname+'%'])
    
  • 0

    你不需要围绕 ? 使用括号,所以你可以使用 list 实现你想要的,作为 execute 的第二个参数:

    cur = conn.execute('SELECT * FROM seo_info WHERE url LIKE ?', ['%' + sheetname + '%'])
    

    tuple

    cur = conn.execute('SELECT * FROM seo_info WHERE url LIKE ?', ('%' + sheetname + '%'),)
    

相关问题