我正在尝试编写一个 PL/SQL 函数,它返回一个整数数组,然后能够使用 cx_Oracles callfunc 调用它。我想我的 PL/SQL 函数是正确的,但我不知道如何用 cx_Oracle 调用它。
create or replace type test_type is table of NUMBER(10);
create or replace function test_function (n in INTEGER)
RETURN test_type
AS
tmp_tab test_type := test_type();
BEGIN
tmp_tab.EXTEND(n);
FOR i IN 1 .. n LOOP
tmp_tab(i) := i;
END LOOP;
RETURN tmp_tab;
END;
它适用于 sqlplus:
SQL> select test_function(20) from dual;
TEST_FUNCTION(20)
--------------------------------------------------------------------------------
TEST_TYPE(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
如何使用 cx_Oracle 获得此类函数的结果?那可能吗?
我找到了这个http://osdir.com/ml/python.db.cx-oracle/2005-06/msg00014.html但我真的不知道如何使用它。当我将类型定义更改为:
create or replace type test_type is table of NUMBER(10) index by binary_integer;
我得到:警告:类型创建时出现编译错误。
SQL> sho err
Errors for TYPE TEST_TYPE:
LINE/COL ERROR
-------- -----------------------------------------------------------------
0/0 PL/SQL: Compilation unit analysis terminated
1/19 PLS-00355: use of pl/sql table not allowed in this context