【发布时间】:2023-03-05 21:31:01
【问题描述】:
我想在 oracle 中的表中添加多行并将添加的值返回到 python 列表
返回的列为主键,在oracle端生成
我写的代码不起作用,这可以理解,但是我不知道该怎么写。请帮帮我
out_id = cursor.var(cx_Oracle.NUMBER)
batch = []
for i in range(3):
batch.append({'val': i})
ins = 'INSERT INTO table (col1) VALUES (:val) RETURNING table.col2 into :out_id'
cursor.executemany(ins, batch)
print(list_out_id.getvalue())
我收到一个错误
ORA-01036: 非法变量名/编号
【问题讨论】:
-
您能告诉我们您使用的是什么版本的 cx_Oracle 吗?你得到的错误是什么?也请使用 cursor.var() 而不是 cursor.arrayvar() 输出变量
list_out_id。使用cursor.arrayvar()创建的array variable 只能用于具有连续键的PL/SQL 关联数组。要在 cx_Oracle 上执行 RETURNING INTO DML 语句,请通读以下文档:[cx-oracle.readthedocs.io/en/latest/user_guide/…( -
@Sharad 我使用 cx_Oracle 8.0.1 版本。我在问题描述中更改了我的代码
标签: python sqlalchemy cx-oracle sql-returning