我希望将IN子句与使用Python中的cx_Oracle的预准备Oracle语句一起使用。用于Oracle的Oracle准备语句的IN子句cx_Oracle
E.g.查询 - select name from employee where id in ('101', '102', '103')
Python的一面,我有一个列表[101, 102, 103]
我转换为一个字符串这样('101', '102', '103')
和蟒蛇用下面的代码 -
import cx_Oracle
ids = [101, 102, 103]
ALL_IDS = "('{0}')".format("','".join(map(str, ids)))
conn = cx_Oracle.connect('username', 'pass', 'schema')
cursor = conn.cursor()
results = cursor.execute('select name from employee where id in :id_list', id_list=ALL_IDS)
names = [x[0] for x in cursor.description]
rows = results.fetchall()
这是行不通的。难道我做错了什么?