gpt4 book ai didi

sql - 如何从oracle中的To_CHAR获取月份?

转载 作者:行者123 更新时间:2023-12-04 09:43:16 26 4
gpt4 key购买 nike

我正在使用 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'),' double space ',' single space ');

谢谢
干杯,

最佳答案

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

select to_char(sysdate,'DD FMMonth YYYY HH24:MI')
from dual

关于sql - 如何从oracle中的To_CHAR获取月份?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62239905/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com