SQL 从 Oracle 中的日期获取月份名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4497456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 08:38:54  来源:igfitidea点击:

Get month name from date in Oracle

sqloracledate

提问by Niraj Choubey

How to fetch month name from a given date in Oracle?

如何从 Oracle 中的给定日期获取月份名称?

If the given date is '15-11-2010'then I want Novemberfrom this date.

如果给定的日期是'15-11-2010'我想要November的这个日期。

回答by Michael Pakhantsov

select to_char(sysdate, 'Month') from dual

in your example will be:

在你的例子中将是:

select to_char(to_date('15-11-2010', 'DD-MM-YYYY'), 'Month') from dual

回答by Erich Kitzmueller

to_char(mydate, 'MONTH')will do the job.

to_char(mydate, 'MONTH')会做的工作。

回答by ASIK RAJA A

Try this,

尝试这个,

select to_char(sysdate,'dd') from dual; -> 08 (date)
select to_char(sysdate,'mm') from dual; -> 02 (month in number)
select to_char(sysdate,'yyyy') from dual; -> 2013 (Full year)

回答by I_am_Batman

In Oracle (atleast 11g) database :

在 Oracle(至少 11g)数据库中:

If you hit

如果你打

select to_char(SYSDATE,'Month') from dual;

It gives unformatted month name, with spaces, for e.g. May would be given as 'May '. The string May will have spaces.

它给出了未格式化的月份名称,带有空格,例如 May 将给出为“May”。字符串可能会有空格。

In order to format month name, i.e to trim spaces, you need

为了格式化月份名称,即修剪空格,您需要

select to_char(SYSDATE,'fmMonth') from dual;

This would return 'May'.

这将返回“May”。

回答by 2Rhino53

If you are trying to pull the value from a field, you could use:

如果您尝试从字段中提取值,您可以使用:

select extract(month from [field_name])
from [table_name]

You can also insert day or year for the "month" extraction value above.

您还可以为上面的“月”提取值插入日或年。

回答by Alireza

Try this

尝试这个

select to_char(SYSDATE,'Month') from dual;

for full name and try this

全名,试试这个

select to_char(SYSDATE,'Mon') from dual;

for abbreviation

缩写

you can find more option here:

您可以在此处找到更多选项:

https://www.techonthenet.com/oracle/functions/to_char.php

https://www.techonthenet.com/oracle/functions/to_char.php