Mark Harrison Mark Harrison - 1 year ago 124
Python Question

cx_Oracle: how do I get the ORA-xxxxx error number?

In a try/except block, how do I extract the Oracle error number?

Answer Source
   cursor.execute("select 1 / 0 from dual")
except cx_Oracle.DatabaseError, e:
   error, = e
   print "Code:", error.code
   print "Message:", error.message

This results in the following output:

Code: 1476
Message: ORA-01476: divisor is equal to zero
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download