oracle 如何在oracle中以不同的格式显示日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4202828/
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-10 02:54:29  来源:igfitidea点击:

How to display date in a different format in oracle

oracledate

提问by trinity

I have a table with a date field. By default, select max(date) from table;returns the date in 'dd-mmm-yy' format. How do I select the date in 'MM/DD/YYYY' format, without changing the table 's structure or the field's format.

我有一个带有日期字段的表。默认情况下,select max(date) from table;以“dd-mmm-yy”格式返回日期。如何选择“MM/DD/YYYY”格式的日期,而不更改 table 的结构或字段的格式。

Thanks, Supraja

谢谢,Supraja

回答by Andrei Co?codan

select to_char(max(date), 'MM/DD/YYYY') from table;

回答by Jens Hoffmann

Try the following:

请尝试以下操作:

select to_char(sysdate,'mm/dd/yyyy') as maxdate from dual;

Some information on the oracle-specific function to_char():

有关 oracle 特定函数 to_char() 的一些信息:

回答by Martin Schapendonk

Check out the to_char function and the date/time formats it accepts.

查看 to_char 函数及其接受的日期/时间格式。

select to_char(sysdate, 'MM/DD/YYYY')
from dual;

回答by GeoKlar

Exists a table or view v$nls_parameters search here the parameter 'NLS_DATE_FORMAT', this is perfect for not be changing the format each while.

存在一个表或视图 v$nls_parameters 在这里搜索参数 'NLS_DATE_FORMAT',这非常适合不每次都改变格式。

SELECT * 
  FROM v$nls_parameters WHERE UPPER(PARAMETER) = 'NLS_DATE_FORMAT';

ALTER SESSION SET NLS_DATE_FORMAT = 'YYYYMMDD'; 

There is also the possibility from make for register of win. in tree

也有可能从 make 注册获胜。在树上

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ORACLE\KEY_OraClient11g_home9

Here key NLS_DATE_FORMAT, change for your format date.

这里关键 NLS_DATE_FORMAT,更改为您的格式日期。