oracle cx_Oracle 和输出变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2698008/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 20:29:01  来源:igfitidea点击:

cx_Oracle and output variables

pythonoracleoracle10gcx-oracle

提问by Tim

I'm trying to do this again an Oracle 10 database:

我正在尝试在 Oracle 10 数据库中再次执行此操作:

cursor = connection.cursor()
lOutput = cursor.var(cx_Oracle.STRING)
cursor.execute("""
            BEGIN
                %(out)s := 'N';
            END;""",
            {'out' : lOutput})
print lOutput.value

but I'm getting

但我得到

DatabaseError: ORA-01036: illegal variable name/number

Is it possible to define PL/SQL blocks in cx_Oracle this way?

是否可以通过这种方式在 cx_Oracle 中定义 PL/SQL 块?

采纳答案by Doug Porter

Yes, you can do anonymous PL/SQL blocks. Your bind variable for the output parameter is not in the correct format. It should be :outinstead of %(out)s

是的,您可以执行匿名 PL/SQL 块。输出参数的绑定变量格式不正确。它应该:out代替%(out)s

cursor = connection.cursor()
lOutput = cursor.var(cx_Oracle.STRING)
cursor.execute("""
            BEGIN
                :out := 'N';
            END;""",
            {'out' : lOutput})
print lOutput

Which produces the output:

产生输出:

<cx_Oracle.STRING with value 'N'>