我希望將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()
這是行不通的。難道我做錯了什麼?