简体   繁体   English

cx_Oracle和输出变量

[英]cx_Oracle and output variables

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块?

Yes, you can do anonymous PL/SQL blocks. 是的,你可以做匿名的PL / SQL块。 Your bind variable for the output parameter is not in the correct format. 输出参数的绑定变量格式不正确。 It should be :out instead of %(out)s 它应该是: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'>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM