开发者

cx_Oracle and output variables

开发者 https://www.devze.com 2022-12-27 18:02 出处:网络
I\'m trying to do this again an Oracle 10 database: cursor = connection.cursor() lOutput = cursor.var(cx_Oracle.STRING)

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

cursor = connection.cursor()
lOutput = cursor.var(cx_Oracle.STRING)
cursor.execute("""
            BEGIN
                开发者_Go百科%(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?


Yes, you can do anonymous PL/SQL blocks. Your bind variable for the output parameter is not in the correct format. It should be :out instead of %(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'>
0

精彩评论

暂无评论...
验证码 换一张
取 消