是否有 Db2 标量函数来检索给定 SQLCODE 的完整错误消息信息?

Is there a Db2 scalar function to retrieve full error message information for a given SQLCODE?

如果我有 SQL 错误代码,我想知道是否有任何现有解决方案可以在代码中获取详细的数据库错误解释。我想将此信息转储到日志中,这样我就不必每次遇到一个都查找 google。

目标转速堆栈是 - Java,DB2。

谢谢!

函数 SYSPROC.SQLERRM 将 return 给定 SQLCODE 的错误消息。 https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.5.0/com.ibm.db2.luw.sql.rtn.doc/doc/r0022027.html

例如这将 return SQLCODE 100 的短消息(即 SQL100W

VALUES (SYSPROC.SQLERRM (100))

像这样

1
---------------------------------------------------------------------------------------------------
SQL0100W  No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table.

  1 record(s) selected.

这将 return 完整的消息

VALUES (SYSPROC.SQLERRM ('SQL100W', '', '', 'en_US', 0))

将return

1                                                                                                                                                                                                                  
----------------------------------------------------------------------------

SQL0100W  No row was found for FETCH, UPDATE or DELETE; or the result of
      a query is an empty table.

Explanation: 

One of the following conditions is true:

*  No row was found that meets the search conditions specified in an
   UPDATE or DELETE statement.

*  The result of a SELECT statement was an empty table.

*  A FETCH statement was executed when the cursor was positioned after
   the last row of the result table.

*  The result of the SELECT used in an INSERT statement is empty.

No data was retrieved, updated, or deleted.

User response: 

No action is required. Processing can continue.

sqlcode: +100

sqlstate: 02000



  1 record(s) selected.