首页 > 解决方案 > 如何在sql oracle中获取月份的名称

问题描述

完整显示日期“14-jul-15”的月份名称。

我尝试了多种方法,但我无法让它显示月份的名称。

标签: sqloracle

解决方案


使用TO_CHAR具有适当格式掩码的函数。

SQL> select to_char(sysdate, 'fm dd-Month-yyyy') result
  2  from dual;

RESULT
------------------
 25-March-2021

SQL>

或者,如果您只有一个 string '14-jul-15',则首先将其转换为有效的日期值(使用TO_DATE),然后TO_CHAR对其应用。

NLS_DATE_LANGUAGE也使用 then 参数,因为我的数据库说克罗地亚语,所以“jul”对我来说是无效月份。你可能不需要它。

SQL> with test (col) as
  2    (select '14-jul-15' from dual)
  3  select
  4    to_char(
  5            to_date(col, 'dd-mon-yy', 'nls_date_language = english'),
  6            'fm dd-Month-yyyy', 'nls_date_language = english'
  7           ) result
  8  from test;

RESULT
------------------
 14-July-2015

SQL>

推荐阅读