由于 Oracle 的 1000 个“IN”子句限制,一种解决方法是使用列表元组。我正在 Python 中尝试此操作,但似乎无法正确绑定列表元组。
我的代码:
mylist = [(1, item1), (1, item2), (1, item3) ... (1, item1500)]
format_strings = ','.join(':%d' % i for i in range(len(mylist)))
query = '''
select x, y, z from table where (1, column_name) IN (%s)
'''%format_strings
with myconnection as connection:
cursor = connection.cursor()
cursor.execute(query, mylist)
result = cursor.fetchall()
...
这给了我错误:cx_Oracle.NotSupportedError:不支持类型元组的 Python 值。
此错误的可能解决方法是什么?谢谢
答案 0 :(得分:0)
您的 python 正在生成以下查询字符串...
select x, y, z from table where (1, column_name) IN (:0,:1,:2,...,:n)
然后您尝试提供一个元组列表作为参数。
也许改为生成这个字符串,并为参数提供一个简单的列表...
select x, y, z from table where (1, column_name) IN ((1,:0),(1,:1),(1,:2),...,(1,:n))
例如...
mylist = [item1, item2, item3, ..., item1500]
format_strings = ','.join('(1,:%d)' % i for i in range(len(mylist)))
query = '''
select x, y, z from table where (1, column_name) IN (%s)
'''%format_strings
with myconnection as connection:
cursor = connection.cursor()
cursor.execute(query, mylist)
result = cursor.fetchall()
...