Python cx_Oracle使用 executemany() 加载 CSV 会给出"Required argument 'parameters' (pos 2) not found"



我的目的是使用 Python 将 csv 文件加载到 Oracle 表中。

  1. 如果数据已经存在,我正在截断表 - 这正在工作

  2. 我正在检查计数以进行测试 - 这正在工作

  3. 我正在尝试将数据从文件插入到甲骨文中。我遇到问题:

    "找不到必需的参数'参数'(位置 2)">

法典:

import cx_Oracle
import pandas as pd 
column_names = 
['Col1','Col2','Col3','Col4','Col5','Col6','Col7','Col8','Col9']
df = pd.read_csv(r"C:Usersfile.dat", names=column_names, sep='|')
dsn_tns = cx_Oracle.makedsn('*', '*', sid='*') 
conn = cx_Oracle.connect(user='*', password='*', dsn=*) 
c = conn.cursor()
c.execute('Truncate table Table_Name')
c.execute('select count(1) from Table_Name')
for row in c:
print(row)        
for lines in df:
c = conn.cursor()
print("I want to print lines")
res = c.executemany("""Insert into Code_Extract (OPERATION,
LIST_COUNTRY_ID,LIST_CODE,SOURCE_SYSTEM_CODE,CODE_USUAL,
INT_LIST_CODE,INT_MDM_CODE,CODE_STATUS,MDM_CODE) 
Values(df['col1'],df['Col2'],df['Col3'],df['Col4'],df['Col5'],df['Col6'],df['Col7'],df['Col8'],df['Col9'])""")
conn.commit()
c.execute('select count(1) from Table_Name')
for row in c:
print(row)
c.close()
conn.commit()
conn.close()

我的期望是,每当我收到文件时,它都应该从指定的路径自动加载到 Oracle 中。

执行many()的参数确实是必需的。有关详细信息,请参阅文档。

您已将参数放在 SQL 中,但应将它们指定为绑定变量,如values (:1, :2, :3, :4, :5, :6, :7, :8, :9).然后,您将数据作为序列列表传递给 executemany()。希望这是清楚的!您可以在此处查看示例。

相关内容

最新更新