Skip to content

View Oracle dbms_output with Python

by Terry Moore on June 18th, 2010

After doing lots of searching on the Internet for how to get the dbms_output from an Oracle SQL query with Python I finally found something.

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()
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Add to favorites
  • FriendFeed
  • MySpace
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Yahoo! Bookmarks

Related Posts

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS