在try / except块中,如何提取Oracle错误号?
答案 0 :(得分:10)
try:
cursor.execute("select 1 / 0 from dual")
except cx_Oracle.DatabaseError, e:
error, = e
print "Code:", error.code
print "Message:", error.message
这导致以下输出:
Code: 1476
Message: ORA-01476: divisor is equal to zero