You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用cx_Oracle向Oracle批量更新数据遇ORA-01484错误求助

Fixing ORA-01484 Error in Oracle Update Statement

Hey there! Let's break down what's going wrong here and get your update working properly.

First, let's pinpoint the core issue in your code: you've mixed up the order of the parameters passed to the execute statement.

In your SQL statement:

update TRANSFERS_TXN_MT set CLASS_RESULT = :1 where id= :2

:1 is intended for the value of CLASS_RESULT (from class_db_col), and :2 is for the id (from class_id_col). But in your loop, you're passing (class_id_col[i], class_db_col[i])—meaning you're putting the ID into the first parameter slot and the class value into the second, which doesn't align with your SQL structure. This mismatch is likely triggering the ORA-01484 error.

Let's fix that first with cleaner, error-resistant code:

Corrected Single-Row Loop Code

statement = 'update TRANSFERS_TXN_MT set CLASS_RESULT = :1 where id= :2'
# Use zip to pair values clearly instead of indexing
for db_val, id_val in zip(class_db_col, class_id_col):
    cursor.execute(statement, (db_val, id_val))
conn.commit()

Bonus: Optimize with Batch Updates

Since you're updating 100 rows, running 100 separate execute() calls isn't the most efficient. Instead, use batch binding to send all updates in one go—this cuts down on database round-trips and is faster overall. Here's how:

statement = 'update TRANSFERS_TXN_MT set CLASS_RESULT = :1 where id= :2'
# Create a list of parameter tuples
params = list(zip(class_db_col, class_id_col))
# Execute all updates in one batch
cursor.executemany(statement, params)
conn.commit()

executemany() is built exactly for bulk operations like this—it takes a list of parameter tuples and runs the statement for each entry. This approach also avoids the ORA-01484 error because we're using the correct parameter order and the proper method for bulk updates.

To recap the ORA-01484 error: it typically occurs when there's a mismatch between parameter binding and Oracle's expectations (like incorrect parameter order, type mismatches, or trying to bind arrays to non-PL/SQL statements). Fixing the parameter order and using executemany() for bulk operations should resolve this completely.

内容的提问来源于stack exchange,提问作者theNextBigThing

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:10:19