【问题标题】:Get implicit results made available from a PL/SQL block or procedure without the use of OUT ref cursor parameters在不使用 OUT 引用游标参数的情况下,从 PL/SQL 块或过程中获取隐式结果
【发布时间】:2017-02-28 16:51:46
【问题描述】:

在低于 12 的 Oracle 版本中调用存储过程后,如果不使用 OUT ref 游标参数,我将无法从 PL/SQL 块或过程中获得隐式结果。

我使用的cx_Oracle 版本是5.2.1。 Python 版本是 2.7。

connection = cx_Oracle.connect(con_param)
cursor_e = connection.cursor() 
cursor_e.callproc('my_proc_name',(tstart,tend,falseVar))

我什至尝试过这个解决方案

        plsql = """declare 
            c1 sys_refcursor;           
            begin
                    open c1 for 
                    execute my_proc(tstart,tend,falseVar)
                    dbms_sql.return_result(c1);
            end;"""
        cursor_e.execute(plsql)

        for ix, resultSet in enumerate(cursor_e.getimplicitresults()):
            print("Result Set #" + str(ix + 1))
            for row in resultSet:
                print(row)
            print()

上面的代码出现以下错误。 捕获的错误:ORA-06550:第 5 行,第 14 列: PLS-00103:在预期以下情况之一时遇到符号“my_proc_name”:

。 ( * @ % & = - + ; at in 是 mod 余数不是 rem or != or ~= >= and or like like2 like4 likec 在使用 || 之间multiset member submultiset 符号“.”被替换为“my_proc_name”以继续。

当我稍微改变上面的代码时

         plsql = """declare 
            c1 sys_refcursor;           
            begin
                    open c1 for 
                    my_proc(tstart,tend,falseVar);
                    dbms_sql.return_result(c1);
            end;"""
        cursor_e.execute(plsql)

我收到以下错误

捕获错误:ORA-06550:第 5 行,第 6 列: PLS-00222:此范围内不存在名为“my_proc_name”的函数 ORA-06550:第 4 行,第 16 列: PL/SQL:语句被忽略 ORA-06550:第 6 行,第 15 列: PLS-00302:必须声明组件“RETURN_RESULT” ORA-06550:第 6 行,第 6 列: PL/SQL:语句被忽略

这个过程大约有 300 行,包含大量逻辑。我不能只取出 SQL 并执行它。

【问题讨论】:

    标签: python cx-oracle


    【解决方案1】:

    隐式结果仅在 Oracle 12.1 和 cx_Oracle 5.3(尚未发布)中可用。在此之前,您实际上必须使用 REF 游标参数。

    这是一个使用隐式结果的示例。

    # using a PL/SQL anonymous block but this could also
    # be a stored procedure
    cursor.execute("""
            declare
                c1 sys_refcursor;
                c2 sys_refcursor;
            begin
    
                open c1 for
                select * from Table1;
    
                dbms_sql.return_result(c1);
    
                open c2 for
                select * from Table2;
    
                dbms_sql.return_result(c2);
    
            end;""")
    
    # display results
    for ix, resultSet in enumerate(cursor.getimplicitresults()):
        print("Result Set #" + str(ix + 1))
        for row in resultSet:
            print(row)
        print()
    

    【讨论】:

    • 当然。对于隐式结果还是 REF 游标?
    • 在不使用 OUT ref 游标参数的情况下获取过程游标。我试图游标的存储过程定义如下。创建或替换过程 my_proc_name (start_dt varchar2, end_dt varchar2, debug boolean) 谢谢,感谢您的帮助。
    • 请检查我的代码并让我知道我是否正确调用了程序。谢谢你。 plsql = """declare c1 sys_refcursor; begin open c1 for execute my_proc_name(tstart,tend,falseVar) dbms_sql.return_result(c1); end;""" cursor_ebay.execute(plsql) for ix, resultSet in enumerate(cursor_ebay.getimplicitresults ()): print("Result Set #" + str(ix + 1)) for resultSet 中的行: print(row) print()
    • 这段代码很难阅读。通常您要打开一个选择语句,而不是调用存储过程。如果调用存储过程,则需要直接在其中使用 ref 游标。请使用代码更新您的问题,使其可读。您还需要在其他程序中包含正在发生的事情。
    猜你喜欢
    • 2016-01-20
    • 1970-01-01
    • 2022-10-12
    • 2022-01-05
    • 1970-01-01
    • 2011-10-16
    • 2011-01-26
    • 1970-01-01
    • 2020-12-25
    相关资源
    最近更新 更多