我sqlite3在 Python 中使用该包并尝试从名为orders. 我想获取列值以order_date18 结尾的条目(varchar该条目的实际值为“10/20/2018”的列)。根据对类似问题的指导,我构建了如下查询:sql = """SELECT * FROM orders WHERE order_date LIKE %s"""args = ['%' + '18']c.execute(sql, args)但我得到了这个:---------------------------------------------------------------------------OperationalError Traceback (most recent call last)<ipython-input-51-e6a345ebe6eb> in <module> 6 args = ['%' + '18'] 7 ----> 8 c.execute(sql, args) 9 conn.commit() 10 OperationalError: near "%": syntax error我已经尝试通过多种方式构建查询,但每次都遇到相同的错误。根据我浏览过的其他问题,这应该可行。怎么了?
1 回答

德玛西亚99
TA贡献1770条经验 获得超3个赞
您应该?
用作绑定变量的占位符,而不是%s
:
sql = """SELECT * FROM orders WHERE order_date LIKE ?"""
添加回答
举报
0/150
提交
取消