MM-DD-RRRR / MM-DD-YYYY 的區別【Blog 搬家】

myhuaer發表於2010-05-05

MM-DD-RRRR / MM-DD-YYYY 的區別 (Date format)

2005 年 08 月 15日

先各位執行一下下面SQL. 結果會如何呢?

select to_date('05/01/02','YYYY-MM-DD') YYYY ,to_date ('05/01/02','RRRR-MM-DD') RRRR
from dual
結果如下:
-------------------------------------------------
YYYY RRRR
0005-01-02 00:00:00 2005-01-02 00:00:00
-------------------------------------------------
什麼原因 ?
RR
Yes Lets you store 20th century dates in the 21st century using only two digits.
See Also: Additional discussion on RR datetime format element in the Oracle Database SQL Reference

RRRR
Yes Round year. Accepts either 4-digit or 2-digit input. If 2-digit, provides the same return as RR. If you do not want this functionality, then enter the 4-digit year.
RRRR這邊說得如果你輸入的是2位數字 則會轉換為 四位年,如果是四位年,則保持不變。
而 YYYY 只是將同一位置上的字元轉換為要求的字元,如果為數不夠則用0 補充。
這就是RRRR /YYYY 的區別!
By -myhuaer
 
myhuaer 發表於:2005.08.15 10:50 ::分類: ( Oracle Infomation ) ::閱讀:(491次)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/34596/viewspace-661930/,如需轉載,請註明出處,否則將追究法律責任。

相關文章