oracle 将 DD-MON-YY 转换为 DD/MM/YYYY
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40224008/
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
oracle convert DD-MON-YY to DD/MM/YYYY
提问by kzmlbyrk
I am trying to convert the format of a varchar2 column from 'DD-MON-YY' to 'DD/MM/YYYY'.
我正在尝试将 varchar2 列的格式从“ DD-MON-YY”转换为“ DD/MM/YYYY”。
In example: from '01-JAN-16' to '01/01/2016'
例如:从“ 01-JAN-16”到“ 01/01/2016”
In case you can ask or it may help:
如果您可以询问或可能有帮助:
- 'MON' part is in English however my current NLS settings are in Turkish.
- All the years are after 2000.
- “MON”部分是英文的,但我目前的 NLS 设置是土耳其语。
- 所有年份都在2000年之后。
How can I do this? Thanks in advance..
我怎样才能做到这一点?提前致谢..
回答by mathguy
If you don't provide the NLS_DATE_LANGUAGE
parameter, your own session's parameter will be used.
如果您不提供NLS_DATE_LANGUAGE
参数,将使用您自己的会话参数。
You can override that like so:
您可以像这样覆盖它:
select TO_CHAR(TO_DATE('01-JAN-16','DD-MON-YY', 'NLS_DATE_LANGUAGE = English'),
'DD/MM/YYYY') from dual;
This will affect only this query, nothing else. If you need to work with many dates like this,
这只会影响这个查询,不会影响其他任何东西。如果你需要处理很多这样的日期,
ALTER SESSION SET NLS_DATE_LANGUAGE='ENGLISH'
- then you can change it back later, or it will reset to Turkish when this session ends and you start another session.
- 然后您可以稍后将其更改回来,或者在此会话结束并开始另一个会话时它会重置为土耳其语。
If you need this change to be made (almost) permanent, put it in your settings in SQL Developer or Toad, or the login.sql for SQL*Plus.
如果您需要(几乎)永久进行此更改,请将其放入 SQL Developer 或 Toad 的设置中,或者将其放入 SQL*Plus 的 login.sql 中。
回答by DCookie
Try this:
尝试这个:
TO_CHAR(TO_DATE('01-JAN-16','DD-MON-YY'),'DD/MM/YYYY')
Your data must be clean - everything must conform to the original format or you'll encounter errors on the TO_DATE conversion.
您的数据必须干净 - 一切都必须符合原始格式,否则您将在 TO_DATE 转换中遇到错误。
回答by Ashish S
Go to Tools —> Preferences —> Database —-> NLS —> Date Format and change date to DD/MM/YYYY .
转到 Tools —> Preferences —> Database —-> NLS —> Date Format 并将日期更改为 DD/MM/YYYY 。
Oracle SQL Developer Version 18.4.0.376 Build 376.1900
Oracle SQL Developer 版本 18.4.0.376 内部版本 376.1900