1

我正在为 DB2 使用 IDAA。在某一时刻,我使用 TO_DATE 来转换一些日期并且它可以工作:

TO_DATE('09/03/2018 06:49:23','MM/DD/YYYY HH:MI:SS')

但是当我在时间戳中有一个以毫秒为单位的 VARCHAR 值时,TO_DATE 会返回一个错误。我在网上环顾四周,找到了一个使用 TO_TIMESTAMP 的答案,但这不起作用:

TO_TIMESTAMP('09/03/2018 06:49:23.443000','MM/DD/YYYY HH:MI:SS.NNNNNN')

我已经查看了这里的每个答案并尝试了许多变体。我已经尝试过 TO_TIMESTAMP、TO_DATE、TIMESTAMP_FORMAT 函数的每一种组合,以及 FF、FF6、NNNNNN 的毫秒格式。我收到这些错误:

NO AUTHORIZED FUNCTION NAMED TO_TIMESTAMP HAVING COMPATIBLE ARGUMENTS WAS FOUND. SQLCODE=-440

SQL error: SQLCODE = -904, SQLSTATE = 57011, SQLERRMC = Invalid Date.. SQLCODE=-904

也许 IDAA 不一样?我不知道。

我正在使用 IBM Data Studio 4.1.3 运行 DB2 for z/OS V11。

4

2 回答 2

0

TIMESTAMP_FORMAT for Db2 for z/OS is documented here

https://www.ibm.com/support/knowledgecenter/en/SSEPEK_12.0.0/sqlref/src/tpc/db2z_bif_timestampformat.html

Do note that HH is the same as HH12, not HH24, so it might be that you need, e.g.

$ db2 "values TIMESTAMP_FORMAT('09/03/2018 16:49:23','MM/DD/YYYY HH24:MI:SS')"

1                         
--------------------------
2018-09-03-16.49.23.000000

  1 record(s) selected.

( The above is from Db2 LUW, but I would assume that function works the same on Db2 for z/OS/ and DAA )

于 2019-06-26T21:59:02.390 回答
0

基于以下链接 - https://www.ibm.com/support/knowledgecenter/en/SS4LQ8_4.1.0/com.ibm.datatools.aqt.doc/gui/concepts/c_idaa_inconsistencies.html

IBM Db2 Analytics Accelerator for z/OS 不支持 Db2 支持的所有日期和时间格式。如果使用 VARCHAR_FORMAT 或 TIMESTAMP_FORMAT 标量函数,这可能会导致加速和内部 Db2 查询的不同结果。IBM Db2 Analytics Accelerator for z/OS 不支持以下格式:

FF[n] - fractional seconds (000000-999999)

The optional number n is used to specify the number of digits to include in the return value. Valid values for n are the integers from 1-6. The default is 6.
ID - ISO day of the week (1-7)

The value 1 represents Monday. The value 7 represents Sunday.
IYYY - ISO year (0000-9999)

The last four digits of the year based on the ISO week that is returned.
NNNNNN - microseconds (000000-999999)

This format is equivalent to FF6.
RR - last two digits of the year (00-99)
SSSSS - seconds since the previous midnight
于 2019-06-28T15:04:46.877 回答