Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python cx\U oracle:是否可以调用函数返回列表?_Python_Oracle_Plsql_Cx Oracle - Fatal编程技术网

Python cx\U oracle:是否可以调用函数返回列表?

Python cx\U oracle:是否可以调用函数返回列表?,python,oracle,plsql,cx-oracle,Python,Oracle,Plsql,Cx Oracle,我正在尝试编写一个PL/SQL函数,该函数返回一个整数数组,然后能够使用cx_Oracles callfunc调用它。我想我正确地使用了PL/SQL函数,但我不知道如何使用cx\U Oracle调用它 创建或替换型式试验类型为编号表(10) 它与sqlplus配合使用: SQL> select test_function(20) from dual; TEST_FUNCTION(20) ---------------------------------------------------

我正在尝试编写一个PL/SQL函数,该函数返回一个整数数组,然后能够使用cx_Oracles callfunc调用它。我想我正确地使用了PL/SQL函数,但我不知道如何使用cx\U Oracle调用它

创建或替换型式试验类型为编号表(10)

它与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获得此类函数的结果?可能吗

我发现了这个,但我真的不知道如何使用它。当我将类型定义更改为:

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

类似于

import cx_Oracle

db_sid = 'db_sid'
db_usr = 'schema'
db_pwd = 'passwd'

conn_data = str('%s/%s@%s') % (db_usr, db_pwd, db_sid)

try:
    db = ora.connect(conn_data)
    except ora.DatabaseError, e:
    error, = e
    ORAmessage = error.message.rstrip("\n")
    print "DatabaseError: %s" % ORAmessage
else:
    cursor = db.cursor()
    try:
        out_parameter = cursor.var(cx_Oracle.NUMBER)
        # calling function to retrieve results until 20
        execute_func  = cursor.callfunc('test_function', out_parameter, [20])
        print str(return_value.getvalue())
    except ora.DatabaseError, exc:
        error, = exc
        ORAmessage = error.message.rstrip("\n")
        print "DatabaseError: %s" % ORAmessage
    cursor.close()

db.close()
阅读本部分
也会很有用。

import cx_Oracle

db_sid = 'db_sid'
db_usr = 'schema'
db_pwd = 'passwd'

conn_data = str('%s/%s@%s') % (db_usr, db_pwd, db_sid)

try:
    db = ora.connect(conn_data)
    except ora.DatabaseError, e:
    error, = e
    ORAmessage = error.message.rstrip("\n")
    print "DatabaseError: %s" % ORAmessage
else:
    cursor = db.cursor()
    try:
        out_parameter = cursor.var(cx_Oracle.NUMBER)
        # calling function to retrieve results until 20
        execute_func  = cursor.callfunc('test_function', out_parameter, [20])
        print str(return_value.getvalue())
    except ora.DatabaseError, exc:
        error, = exc
        ORAmessage = error.message.rstrip("\n")
        print "DatabaseError: %s" % ORAmessage
    cursor.close()

db.close()
阅读本部分
也将很有用。

此行中的返回值:
execute\u func=cursor.callfunc('test\u function',return\u value,[20])
未定义。应该是什么?不幸的是这不起作用。我得到>>>execute_func=cursor.callfunc('test_function',out_参数,[20])回溯(最近一次调用):文件“”,第1行,在cx_Oracle中。数据库错误:ORA-06550:第1行,第13列:PLS-00382:表达式的类型错误ORA-06550:第1行,第7列:PL/SQL:语句ignoredIt's,因为您返回的是*test_type*(1,2,3,4,…)不访问数据库中的数字列。尝试将cx\u Oracle.NUMBER切换为cx\u Oracle.OBJECT.>>>out\u parameter=cursor.var(cx\u Oracle.OBJECT)回溯(最近一次调用):类型错误:对象变量需要类型名称很抱歉,我没有进一步的帮助,我的PL/SQL经验非常有限,我通常使用.cursor.callfunc访问过程和函数,没有问题。此行中的返回值:
execute\u func=cursor.callfunc('test\u function',return\u value,[20])
未定义。应该是什么?不幸的是这不起作用。我得到>>>execute_func=cursor.callfunc('test_function',out_参数,[20])回溯(最近一次调用):文件“”,第1行,在cx_Oracle中。数据库错误:ORA-06550:第1行,第13列:PLS-00382:表达式的类型错误ORA-06550:第1行,第7列:PL/SQL:语句ignoredIt's,因为您返回的是*test_type*(1,2,3,4,…)不访问数据库中的数字列。尝试将cx\u Oracle.NUMBER切换到cx\u Oracle.OBJECT.>>>out\u parameter=cursor.var(cx\u Oracle.OBJECT)回溯(最近一次调用):类型错误:对象变量需要类型名很抱歉,我没有进一步的帮助,我的PL/SQL经验非常有限,我通常使用.cursor.callfunc访问过程和函数,没有任何问题。