【发布时间】:2019-12-03 10:38:10
【问题描述】:
前段时间有一个类似的question。我尝试遵循建议的结果:
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
那么我错过了什么?
【问题讨论】:
-
在 the linked question 中,答案都使用 PL/SQL 关联数组 (
TYPE name AS TABLE OF INT INDEX BY PLS_INTEGER) 并且不使用 SQL 集合作为传递的数据类型。这几乎肯定是该问题的重复。 documentation forcursor.arrayvar没有明确说明它是仅适用于 PL/SQL 关联数组还是也适用于 SQL 集合,所以我将保持打开状态,以防有人可以发布后者的示例。 -
感谢您指出 PL/SQL 关联数组和 SQL 集合之间的差异方向。这是我忽略的一点(对我来说是新的)。
标签: python oracle plsql cx-oracle user-defined-types