cx_Oracle:如何获取ORA-xxxxx错误号?

时间:2008-09-02 20:40:30

标签: python oracle cx-oracle

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

1 个答案:

答案 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