请教cursor.execute传两个相同参数如何解决

wobushilegend 2019-04-10 06:07:21
a = '2019-04-09'
sql = """
select *
from
table
where substr(created_at,1,10) = %s
and substr(updated_at,1,10) = %s
"""
cursor.execute(sql,a)

报错Unsupported param format: 2019-04-09
请问怎么改呢
...全文
303 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
陈年椰子 2019-04-11
  • 打赏
  • 举报
回复

a = '2019-04-09'
sql = """
select *
from
table
where substr(created_at,1,10) = '%s'
and substr(updated_at,1,10) = '%s'
"""
cursor.execute(sql,a)

或者这样

a = '2019-04-09'
sql = """
select *
from
table
where substr(created_at,1,10) = '%s'
and substr(updated_at,1,10) = '%s'
"""
cursor.execute(sql,(a,a,))

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧