Python cx_Oracle 中 Oracle Prepared Statement 的 IN 子句

van*_*d39 5 python oracle cx-oracle prepared-statement

我想在 Python 中使用 cx_Oracle 将 IN 子句与准备好的 Oracle 语句一起使用。

例如查询 - 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()
Run Code Online (Sandbox Code Playgroud)

这不起作用。难道我做错了什么?

Ant*_*nga 5

Oracle 不支持这个概念——而且您也绝对不是第一个尝试这种方法的人!您必须: