通过pyodbc将行插入Oracle数据库时出错(LONG值/ LONG列)

时间:2017-03-30 21:57:44

标签: python oracle11g pyodbc

我在尝试将元组列表中的多行插入Oracle表时遇到问题。

以下是用于创建表的相关SQL:

CREATE TABLE test_table (
column_1 NUMBER,
column_2 NUMBER
);

这是我用来将元组列表中的记录插入表中的python代码。

import pyodbc
cnxn = pyodbc.connect(Driver='{Oracle in OraClient11g_home1}', DBQ='somedatabase',
                      UID=username, PWD=password, autocommit=True)
cursor = cnxn.cursor()

payload1 = (2.0, 4.0)
payload2 = (3.0, 6.0)
payload = [payload1, payload2]

# 1. this inserts (2.0, 4.0) into table
cursor.execute("insert into test_table (column_1, column_2) values (?, ?);", payload1)

# 2. this inserts (3.0, 6.0) into table
cursor.execute("insert into test_table (column_1, column_2) values (?, ?);", payload2)

# 3. error, only inserts (2.0, 4.0) into table
cursor.executemany("insert into test_table (column_1, column_2) values (?, ?);", payload)

# 4. error, only inserts (2.0, 4.0) into table
for item in payload:
    cursor.execute("insert into test_table (column_1, column_2) values (?, ?);", item)

单个记录插入工作正常,但是当我尝试executemany或循环遍历每个项目并执行单个执行时,我收到以下错误:

Error: ('HY000', '[HY000] [Oracle][ODBC][Ora]ORA-01461: can bind a LONG value only for insert into a LONG column\n (1461) (SQLExecDirectW)')

是否有其他人遇到此问题或有解决方案?

0 个答案:

没有答案