格式化在oracle中的DATE [英] Formatting DATE in oracle
问题描述
我想创建一个日期字段,其中包含dd-MMM-yy格式的日期。不为null,然后将其更改为yyyy / mm / dd格式
但问题是oracle不接受dd-MMM-yy格式化日期作为输入参数,
它说:请使用yyyy-MM-dd日期格式!!!
我如何首先将dd-MMM-yy formate更改为yyyy-MM- dd so oracle接受它作为输入,然后将其更改为yyyy / mm / dd
:请使用yyyy-MM-dd日期格式!!!
这与Oracle错误无关。
我在dd-MMM-yy格式中包含日期的表格中有一个日期字段。
不,你很困惑。 Oracle不会以您看到的格式存储日期。它将内部存储在 7个字节中,每个字节存储 datetime 值的不同组件。
字节说明
---- ---------------------------------- ---------------
1世纪价值,但在存储之前添加100
2存储
之前添加年份和100添加到$ b $ 3 3
4月的日子
5小时,但在存储之前添加1
6分钟,但在存储之前添加1
7秒,但在存储之前添加1
如果要显示,请使用正确的格式模型使用 TO_CHAR 。
插入时,请使用格式模型 TO_DATE 。
默认情况下,您看到的格式是您的区域设置特定NLS设置。
SQL>选择参数,值从v $ nls_parameters,其中parameter ='NLS_DATE_FORMAT';
参数值
--------------- --------------------- -------------------------------------------
NLS_DATE_FORMAT DD- MON-RR
SQL>从双重选择sysdate;
SYSDATE
---------
03-FEB-15
SQL>从双重选择to_char(sysdate,'mm / dd / yyyy hh24:mi:ss')
TO_CHAR(SYSDATE,'MM
-------------------
02/03/2015 17:59: 42
SQL>
更新 strong> MMM 格式。
如果您的意思是月份名称最多三个字符,请使用 MON 。 p>
I have a date field in a table that contains date in dd-MMM-yy format .
I want to create a function that get this date check it for not null and then change it to yyyy/mm/dd format
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 !!!
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
: Please Use yyyy-MM-dd date format !!!
That is no way related to an Oracle error.
I have a date field in a table that contains date in dd-MMM-yy format .
No, you are confused. Oracle does not store dates in the format you see. It stores it internally in 7 bytes with each byte storing different components of the datetime value.
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_CHAR with proper FORMAT MODEL.
While inserting, use TO_DATE with proper FORMAT MODEL.
What you see as a format by default, is your locale specific NLS settings.
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>
Update Regarding MMM format.
By MMM if you mean the month name up to three characters, then use MON.
这篇关于格式化在oracle中的DATE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!