如何在Oracle中将日期时间字符串末尾添加三个零?

huangapple go评论68阅读模式
英文:

How to add three zeroes to the end of a datetime string in Oracle?

问题

我有这样的数据 2020/08/05 05:34:05.000,我尝试使用 to_char(column,'YYYY/MM/DD HH24:MI:SS.FF3') 来获得类似的输出,但出现了错误 "日期格式无法识别"。如何在秒后附加这些000?

我尝试使用 to_char(column,'YYYY/MM/DD HH24:MI:SS'),它给我 2020/08/05 05:34:05,但我想要在末尾附加三个零,是否可以在不硬编码零的情况下实现?

英文:

I have data like this 2020/08/05 05:34:05.000 i tried to get the similar output by using to_char(column,'YYYY/MM/DD HH24:MI:SS.FF3') getting error "Date format not recognized". how to append these 000 at the end after seconds ?

I tried using to_char(column,'YYYY/MM/DD HH24:MI:SS') which gives me 2020/08/05 05:34:05 but i want three zeroes should append at the end is it possible without hardcoding zeroes to get the 000 ?

答案1

得分: 1

看起来列的数据类型是 DATEDATE 数据类型不支持小数秒,但你可以将其转换为 TIMESTAMP

to_char(CAST(column AS TIMESTAMP), 'YYYY/MM/DD HH24:MI:SS.FF3')
英文:

Looks like the column datatype is DATE. DATE datatype does not support fractional seconds but you can cast it into a TIMESTAMP.

to_char(CAST(column AS TIMESTAMP), 'YYYY/MM/DD HH24:MI:SS.FF3')

huangapple
  • 本文由 发表于 2023年6月5日 14:08:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76403866.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定