我试图在SQL组件中传递一个python整数列表。我已经看了前面的问题,但没有一个能帮我解决错误。以下是我正在做的:
import cx_Oracle
SQL_Components = '''
SELECT /*+ FIRST_ROWS materialize */
xxx,
xxx
FROM
xxx
INNER JOIN xxx
INNER JOIN xxx
INNER JOIN xxx
INNER JOIN xxx
WHERE
tpr.tpr_name LIKE 'M39AAA%' AND mml.mml_name IN (%s)
'''
def get_TPM_IDsDict():
global chosen_lot
chosen_lot=[]
print ("Executing: get_TPM_IDsDict")
f = open("XXX.txt", "r")
for line in f:
chosen_lot.append(line.strip())
chosen_lot = ["'%s'" % x for x in chosen_lot]
Cursor.execute(SQL_Components % ("','".join(chosen_lot)))
我得到这个错误:
Cursor.execute(SQL_Components % ("','".join(chosen_lot)))
ValueError: unsupported format character ''' (0x27) at index 580
考虑{{CD1}}支持的编号参数。另外,确保在
cursor.execute
的第二个参数中实际传入参数值。不要覆盖你的价值观在所有Python DB API(} 或F-strings(Python 3.6+)
cxOracle
、ibm_db
、psycopg2
、pyodbc
等)中,不应引用参数占位符。此外,在Python中,通常避免使用%
进行字符串插值,因为它是de-emphasised (not officially deprecated yet)。相反,使用^{相关问题 更多 >
编程相关推荐