如何从Oracle的To_CHAR获取月份?

问题描述 投票:2回答:1

我正在使用To_Char将日期转换为以下格式的字符串:

To_char(Date,'DD Month YYYY HH24:MI')

这很好用,但是它返回带有空格的月份。我想它的设计目的是使所有月份的字符串都具有相同的长度:

当前结果

01 January  2020 13:15
01 February 2020 13:15
01 March    2020 13:15       << Spaces after the month string
01 April    2020 13:15       << Spaces after the month string
01 May      2020 13:15       << Spaces after the month string
01 June     2020 13:15       << Spaces after the month string

所需结果

01 January 2020 13:15
01 February 2020 13:15
01 March 2020 13:15       << No spaces after the month string
01 April 2020 13:15       << No spaces after the month string
01 May 2020 13:15         << No spaces after the month string
01 June 2020 13:15        << No spaces after the month string

有人知道如何直接从To_char函数中实现吗? (无需进行某些特定的字符串替换,例如replace(To_char(Date,'DD Month YYYY HH24:MI'),'双空格','单空格');

谢谢干杯,

sql oracle
1个回答
2
投票

您可以在fm上使用month修饰符:

select to_char(sysdate,'DD FMMonth YYYY HH24:MI')
from dual
© www.soinside.com 2019 - 2024. All rights reserved.