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

从cx_Oracle 8.1.0迁移到oracledb 2.5.1时,绑定参数按数组索引复用报错的问题求助

从cx_Oracle 8.1.0迁移到oracledb 2.5.1时,绑定参数按数组索引复用报错的问题求助

我最近在把项目里的cx_Oracle 8.1.0替换成oracledb 2.5.1,结果碰到了个棘手的问题。之前用cx_Oracle的时候,下面这段更新数据的逻辑跑起来完全正常:

对应的SQL语句是这样的:

update command_center set 
            E_ID = :1,
            E_ASPECTS = :2,
            E_CREATED_TIMESTAMP = :3
WHERE e_id = :1

执行批量更新的Python代码如下:

def bulk_insert_or_update_data_to_targets(self, sql, target_data, id_index=0):
    for target_connections, data in target_data:
        for con in target_connections:
            cursor = con.cursor()
            cursor.executemany(sql, data, batcherrors=True)
            if cursor.getbatcherrors():
                self.logger.debug("data: " + str(data))
            cursor.close()

但换成oracledb 2.5.1之后,每次执行都会抛出这个异常:

oracledb.exceptions.DatabaseError: DPY-4009: 4 positional bind values are required but 3 were provided

之前在cx_Oracle里,我可以复用同一个位置索引的参数——就像这里的:1,只需要在数据数组里传一次对应的值就行,不用重复传递。想问下有没有办法让oracledb也保持这个行为,还是说现在必须要修改SQL语句或者传参的方式才能解决这个问题?

备注:内容来源于stack exchange,提问作者bilak

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 11:18:09