[英]Oracle - Extract last month name from sysdate
If the date in my record is '04-NOV-2021', for ex, I want to show 'October'.如果我记录中的日期是“04-NOV-2021”,例如,我想显示“October”。
select extract(MONTH FROM add_months(sysdate,-1)) from dual;
That code will give me the '10' for October, but how do I format it as 'October'?该代码将为我提供 10 月的“10”,但如何将其格式化为“10 月”?
One option is to use to_char
with the right nls_language
.一种选择是将
to_char
与正确的nls_language
一起使用。
SQL> select to_char(sysdate,'Month', 'nls_language=''english''' ) from dual ;
TO_CHAR(SYSDATE,'MONTH','NLS_LANGUAG
------------------------------------
November
SQL>
In your case在你的情况下
SQL> select to_char(to_date(to_char(add_months(sysdate,-1))),'Month', 'nls_language=''english''' ) from dual ;
TO_CHAR(TO_DATE(TO_CHAR(ADD_MONTHS(S
------------------------------------
October
Or或者
SQL> select to_char(add_months(sysdate,-1), 'fmMonth', 'nls_language="english"') from dual ;
TO_CHAR(ADD_MONTHS(SYSDATE,-1),'FMMO
------------------------------------
October
SQL>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.