[英]DB2 SQL capturing errors on date formating
如果我在 DB2 SQL 日期轉換上遇到錯誤,我可以使用什么語法來捕獲/報告錯誤,同時允許作業繼續。 例如:寫入文件或日志或打印文件?
示例:TIMESTAMP_FORMAT(CHAR(MYDATE)) 其中 MYDATE = '20200132'
錯誤信息:
Message . . . . : Expression not valid using format string specified
for TIMESTAMP_FORMAT.
Cause . . . . . : Argument 1 of the TIMESTAMP_FORMAT function can not
be interpreted using the format string specified in argument 2 for
one of the following reasons:
-- The string expression is too short or too long.
-- The string expression does not conform to the template specified
in the format string.
-- Too many digits were specified in the string expression for the
corresponding format element in the format string.
-- A value in the string expression is not valid for the
corresponding format element in the format string.
Recovery . . . : Specify a valid format string for the function. Try
您可以使用用戶定義的 Function (UDF) 來處理轉換並捕獲錯誤。
無效時返回 NULL,或者可能為 9999999-->9999-12-31。
您可以構建或擁有或查找一些示例代碼。 對於 IBM i 的 Db2,有一個由 Alan Campin 開發的名為iDate的開源庫,被許多人使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.