Python sqlite3在where子句中为select语句传递多个值时出现问题

2024-09-27 23:20:08 发布

您现在位置:Python中文网/ 问答频道 /正文

在select语句的WHERE子句中传递多个值时,我得到的是一个错误,而不是匹配表中的行

错误是: sqlite3.InterfaceError:绑定参数0时出错-可能是不支持的类型

我有一张桌子

runno(int)  value(str)    sample(str)
100         Test File.1   Sample Value is 1
100         Test File.1   Sample Value is 2
100         Test File.2   Sample Value is 200
200         Test File.21  Sample Value is unknown
200         Test File.21  Sample Value is New
searchVal1 = ['Test File.1']
searchVal2 = [100] --- also tried ['100']
cur.execute("SELECT sample FROM table WHERE value=? AND runno=?", (searchVal1,searchVal2))

结果: sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

但是,如果我只在WHERE子句中传递一个值,它就会起作用: cur.execute("SELECT sample FROM table WHERE value=?", (searchVal1))

或者 cur.execute("SELECT sample FROM table WHERE runno=?", (searchVal2))

Sqlite3版本是:3.21.0,python 3.7

我不确定我做错了什么。有人能帮忙吗


Tags: samplefromtestexecuteisvaluetablewhere

热门问题