我愿意使用cx_Oracle在Python中准备好的语句来使用IN子句进行翻译。例如,查询 -
select name from employee where id in ('101', '102', '103')
。在Python侧,我有一个列表[101, 102, 103]
,我将其转换为字符串('101', '102', '103')
并在Python中使用以下代码: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()
这行代码不起作用,我做错了什么吗?