Created
September 24, 2012 00:29
-
-
Save TerryMooreII/3773572 to your computer and use it in GitHub Desktop.
Get Oracle DBMS_Output from Python's cx_Oracle library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cx_Oracle | |
conn = cx_Oracle.Connection("userid/password@tns") | |
curs = conn.cursor() | |
curs.callproc("dbms_output.enable") | |
sqlCode = """ | |
some long | |
sql code | |
with dbms_output | |
""" | |
curs.execute(sqlCode) | |
statusVar = curs.var(cx_Oracle.NUMBER) | |
lineVar = curs.var(cx_Oracle.STRING) | |
while True: | |
curs.callproc("dbms_output.get_line", (lineVar, statusVar)) | |
if statusVar.getvalue() != 0: | |
break | |
print lineVar.getvalue() |
Awesome !!! thanks a lot for this wonderful example . It definitely helps those who are beginners .
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very nice. With
cx_Oracle
v5.2 and Oracle 11g, however, I get a segfault unless I provide an explicit parameter (buffer_size
) fordbms_output.enable
.That is: