cx_oracle:callfunc可以返回列表吗?
我正在尝试编写一个返回整数数组的 PL/SQL 函数,然后能够使用 cx_Oracles callfunc 调用它。我认为我的 PL/SQL 函数是正确的,但我不知道如何用 cx_Oracle 调用它。
创建或替换类型 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
I'm trying to write a PL/SQL function that returns an array of integers and then be able to call it with cx_Oracles callfunc. I think I got the PL/SQL function right, but I don't know how to call it with 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;
It works with 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)
How can I get the result of such function using cx_Oracle? Is that possible?
I've found this http://osdir.com/ml/python.db.cx-oracle/2005-06/msg00014.html but I don't realy know how to use it. When I change my type definition to:
create or replace type test_type is table of NUMBER(10) index by binary_integer;
I get:
Warning: Type created with compilation errors.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
内容
阅读这部分的
手册也很有用。
Something in the lines of,
Reading this part of the
manual will also be useful.