2

在 try/except 块中,如何提取 Oracle 错误号?

4

1 回答 1

12
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
于 2008-09-02T20:41:33.540 回答