cx_Oracle和输出变量

Tim*_*Tim 7 python oracle cx-oracle oracle10g

我正在尝试再次执行Oracle 10数据库:

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

但我得到了

DatabaseError: ORA-01036: illegal variable name/number
Run Code Online (Sandbox Code Playgroud)

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

Dou*_*ter 7

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

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

产生输出:

<cx_Oracle.STRING with value 'N'>
Run Code Online (Sandbox Code Playgroud)