繁体   English   中英

我如何在python sql中传递值列表?

[英]How i can pass a list of values in python sql?

我在IN查询中传递值列表。 当我在工作台和其他地方运行此查询时它正在工作但不在python代码中工作。

在python中,它将值作为列表,因此它给出了一个错误。

我想在Python SQL查询中传递值列表。 但它给了我一个错误:

只能将str(不是“元组”)连接到str

我也尝试使用列表但是它给出了一个错误:

只能将str(不是“list”)连接到str

emp_id = ['470224', '471822', '470551', '471854', '471603', '468121', '458435', '466700', '471605', '471609', '471604', '458535', '454387', '469881']

mycursor.execute("select * from table_name where id in "+"'"+emp_id+"'")

查询必须如下工作:

select * from table_name where id in ('470224', '471822', '470551', '471854', '471603', '468121', '458435', '466700', '471605', '471609', '471604', '458535', '454387', '469881') ;

它必须获取IN查询中的所有记录。

emp_id = ['470224', '471822', '470551', '471854', '471603', '468121', '458435', '466700', '471605', '471609', '471604', '458535', '454387', '469881']
mycursor.execute("select * from table_name where id in " + str(tuple(emp_id)))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM