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

标签 python oracle cx-oracle

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

最佳答案

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

关于python - cx_Oracle : how do I get the ORA-xxxxx error number?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40586/

相关文章:

python - 尝试从 Pandas Dataframe 中删除多行,但删除的行数超出预期

python - Winzip 无法在 Windows 上打开由 python shutdown.make_archive 创建的存档。在 ubuntu 上存档管理器运行良好

mysql - mysql 或 oracle SQL 中日期之间的减少/增加

sql - 选择有条件的日期时间(Oracle)

oracle - 从 python 连接到 oracle 时 sys 用户登录被拒绝

python - `for` 循环到PyTorch中的多维数组

python - 将键列表转换为嵌套字典

java - 如何使用 createRow() 将行添加到 View 对象后删除行

python - cx_Oracle.InterfaceError : Unable to acquire Oracle environment handle in linux

找不到 Python 模块 "cx_Oracle"模块