oracle 格式化日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28298838/
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
Formatting DATE in oracle
提问by OmiD
I have a date field in a table that contains date in dd-MMM-yy format .
我在包含 dd-MMM-yy 格式的日期的表中有一个日期字段。
I want to create a function that get this date check it for not null and then change it to yyyy/mm/dd format
我想创建一个函数,让这个日期检查它是否为空,然后将其更改为 yyyy/mm/dd 格式
but the problem is that oracle doesn't accept dd-MMM-yy formate date as a input parameter and it say : Please Use yyyy-MM-dd date format !!!
但问题是 oracle 不接受 dd-MMM-yy 格式日期作为输入参数,它说:请使用 yyyy-MM-dd 日期格式!!!
how can I first change dd-MMM-yy formate to yyyy-MM-dd so oracle accept it as input then change it to yyyy/mm/dd
我如何首先将 dd-MMM-yy 格式更改为 yyyy-MM-dd,以便 oracle 接受它作为输入然后将其更改为 yyyy/mm/dd
回答by Lalit Kumar B
: Please Use yyyy-MM-dd date format !!!
: 请使用 yyyy-MM-dd 日期格式!!!
That is no way related to an Oracle error.
这与 Oracle 错误无关。
I have a date field in a table that contains date in dd-MMM-yy format .
我在包含 dd-MMM-yy 格式的日期的表中有一个日期字段。
No, you are confused. Oracle does not store dates in the format you see. It stores it internally in 7 byteswith each byte storing different components of the datetimevalue.
不,你糊涂了。Oracle 不会以您看到的格式存储日期。它在内部以7 个字节存储它,每个字节存储日期时间值的不同组成部分。
Byte Description
---- -------------------------------------------------
1 Century value but before storing it add 100 to it
2 Year and 100 is added to it before storing
3 Month
4 Day of the month
5 Hours but add 1 before storing it
6 Minutes but add 1 before storing it
7 Seconds but add 1 before storing it
If you want to display, use TO_CHARwith proper FORMAT MODEL.
如果要显示,请使用TO_CHAR和适当的FORMAT MODEL。
While inserting, use TO_DATEwith proper FORMAT MODEL.
插入时,使用TO_DATE和正确的FORMAT MODEL。
What you see as a format by default, is your locale specific NLS settings.
默认情况下,您看到的格式是特定于语言环境的 NLS 设置。
SQL> select parameter, value from v$nls_parameters where parameter='NLS_DATE_FORMAT';
PARAMETER VALUE
--------------- ----------------------------------------------------------------
NLS_DATE_FORMAT DD-MON-RR
SQL> select sysdate from dual;
SYSDATE
---------
03-FEB-15
SQL> select to_char(sysdate, 'mm/dd/yyyy hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'MM
-------------------
02/03/2015 17:59:42
SQL>
UpdateRegarding MMMformat.
更新关于MMM格式。
By MMM if you mean the month name up to three characters, then use MON.
MMM 如果您指的是最多三个字符的月份名称,则使用MON。