将列表传递给 PL/SQL 过程
Passing list to PL/SQL procedure
前段时间有一个类似的。我试着听从建议,结果是:
Traceback (most recent call last):
File "<input>", line 1, in <module>
cx_Oracle.DatabaseError: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'TEST_ARRAY'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
这是我目前所做的。
1.创建新类型
create type list_ids as table of int;
2。创建测试程序
create or replace procedure test_array(ids in list_ids) is
begin
for i in 1..ids.count
loop
dbms_output.PUT_LINE(ids(i));
end loop;
end;
3。 运行 python 脚本
import cx_Oracle
db = cx_Oracle.connect("my_user", "my_password", "<host>:<port>/<sid>")
cursor = db.cursor()
idl = cursor.arrayvar(cx_Oracle.NUMBER, [1,2,3,4])
cursor.callproc("test_array", parameters=[idl])
Traceback (most recent call last):
File "<input>", line 1, in <module>
cx_Oracle.DatabaseError: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'TEST_ARRAY'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
那我错过了什么?
如上面的评论所述,cursor.arrayvar()
仅可用于 PL/SQL 关联数组,不适用于嵌套表。对于嵌套表格,您将需要使用 "objects" API。这个 example 展示了如何这样做,即使它恰好也用于 PL/SQL 关联数组!
我还调整了 cursor.arrayvar()
的文档以明确它仅适用于具有连续键的 PL/SQL 关联数组。
前段时间有一个类似的
Traceback (most recent call last):
File "<input>", line 1, in <module>
cx_Oracle.DatabaseError: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'TEST_ARRAY'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
这是我目前所做的。
1.创建新类型
create type list_ids as table of int;
2。创建测试程序
create or replace procedure test_array(ids in list_ids) is
begin
for i in 1..ids.count
loop
dbms_output.PUT_LINE(ids(i));
end loop;
end;
3。 运行 python 脚本
import cx_Oracle
db = cx_Oracle.connect("my_user", "my_password", "<host>:<port>/<sid>")
cursor = db.cursor()
idl = cursor.arrayvar(cx_Oracle.NUMBER, [1,2,3,4])
cursor.callproc("test_array", parameters=[idl])
Traceback (most recent call last):
File "<input>", line 1, in <module>
cx_Oracle.DatabaseError: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'TEST_ARRAY'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
那我错过了什么?
如上面的评论所述,cursor.arrayvar()
仅可用于 PL/SQL 关联数组,不适用于嵌套表。对于嵌套表格,您将需要使用 "objects" API。这个 example 展示了如何这样做,即使它恰好也用于 PL/SQL 关联数组!
我还调整了 cursor.arrayvar()
的文档以明确它仅适用于具有连续键的 PL/SQL 关联数组。