时间戳中的微秒数:db2查询

时间:2013-06-03 10:23:40

标签: sql db2 timestamp

我想要时间戳中的微秒,所以我使用的是下面的查询但没有得到微秒

select TIMESTAMP_FORMAT(CURRENT_TIMESTAMP,
       'YYYY-MM-DD HH:MM:SS.NNNNNN') FROM SYSIBM.SYSDUMMY1

获取:2013-06-01 02:45:12 预期输出:2013-06-01 02:45:12.145235

价:http://pic.dhe.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=%2Fcom.ibm.db2z9.doc.sqlref%2Fsrc%2Ftpc%2Fdb2z_bif_timestampformat.htm

2 个答案:

答案 0 :(得分:3)

您似乎使用了错误的功能,即timestamp_format用法是:

  

TIMESTAMP_FORMAT函数返回基于的时间戳   使用指定的格式解释输入字符串。

函数接收字符串并返回时间戳 - 转换按照规范字符串完成。例如:

VALUES (TIMESTAMP_FORMAT('1999-12-31 23:59:59', 'YYYY-MM-DD HH24:MI:SS'))
--------------------------
1999-12-31-23.59.59.000000

将tst转换为字符串可以这样做:

VALUES cast(current_timestamp as varchar(40))
----------------------------------------
2013-06-05-23.19.15.125000

只需使用microsecond函数即可完成微秒:

VALUES( microsecond(current_timestamp), current_timestamp)
----------- --------------------------
     468000 2013-06-05-23.21.10.468000

注意:微秒返回数字,而不是字符串。

答案 1 :(得分:0)

使用这段代码将字符串日期时间转换为时间戳格式

foo