日期:2014-05-16 浏览次数:20543 次
TO_CHAR(<x> [,<fmt >[,<nlsparm>] ]) SELECT TO_CHAR(SYSDATE,'Day Ddspth,Month YYYY' ,'NLS_DATE_LANGUAGE=German') Today_Heute FROM dual; SELECT TO_CHAR(SYSDATE ,'"On the "Ddspth" day of "Month, YYYY') FROM dual; 这里的Dd和DD意思一样,不同点是单词首字母大写,其他小写 TO_CHAR(SYSDATE,'"ONTHE"DDSPTH"DAYOF"MONTH,Y -------------------------------------------- On the Twenty-Seventh day of November , 2002 SP 数字的拼写 ---spelling out TH 数字的序数词 spth 使用序数词来拼写,如12--->twelve(sp方式) -->Twelfth (spth方式) SELECT SYSDATE ,TO_CHAR(SYSDATE,'Mmspth') Month ,TO_CHAR(SYSDATE,'DDth') Day ,TO_CHAR(SYSDATE,'Yyyysp') Year FROM dual; SYSDATE MONTH DAY YEAR ----------- -------- ---- ------------------------------------- 01-DEC-1999 Twelfth 01ST One Thousand Nine Hundred Ninety-Nine 其中01ST是数字的序数词,Twelfth 是数字被拼写后的序数词 Yyyy就是YYYY,但是每个单词首字母大写,其他小写 SELECT TO_CHAR(SYSDATE,'MONTH') upperCase ,TO_CHAR(SYSDATE,'Month') mixedCase ,TO_CHAR(SYSDATE,'month') lowerCase FROM dual; UPPERCASE MIXEDCASE LOWERCASE --------- --------- --------- DECEMBER December december Date Format Codes Date Code | Format Code Description | Example AD or BC Epoch indicator ‘YYYY AD’ = 2002 AD A.D. or B.C. Epoch indicator with periods ‘YYYY A.D.’ = 2002 A.D. AM or PM Meridian indicator ‘HH12AM’ = 09AM A.M. or P.M. Meridian indicator with periods ‘HH A.M.’= 09 A.M. DY Day of week abbreviated Mon, Tue, Fri DAY Day of week spelled out Monday, Tuesday, Friday D Day of week (1–7) 1,2,3,4,5,6,7 DD Day of month (1–31) 1,2,3,4…31 DDD Day of year (1–366) 1,2,3,4…366 FF Fractional seconds .34127 J Julian day (days since 4712BC) 2451514,2451515,2451516 W Week of the month (1–5) 1,2,3,4,5 WW, IW Week of the year, ISO week of the year 1,2,3,4…53 MM Two-digit month 01,02,03…12 MON Month name abbreviated Jan, Feb, Mar…Dec MONTH Month name spelled out January, February… Q Quarter 01-Jan-2002 RM Roman numeral month (I–XII) I,II,III,IV,V…XII YYYY,YYY, Four-digit year; last 3, 2, 1 1999, 999, 99, 9 YY, Y digits in the year 2000, 000, 00, 0 YEAR Year spelled out Two thousand two SYYYY If BC, year is shown as negative -1250 RR Used for data input with only See description two digits for the year following table HH, HH12 Hour of the half-day (1–12) 1,2,3…12 HH24 Hour of the day (0–23) 0,1,2…23 MI Minutes of the hour (0–59) 0,1,2…59 SS Seconds of the minute (0–59) 0,1,2…59 SSSSS Seconds of the day (0–86399) 0,1,2…86399 TZD Time zone daylight savings; CST must correspond to TZR TZH Time zone hour, together 07 with TZM is time zone offset TZM Time zone minute, together 00 with TZH is time zone offset TZR Time zone region US/Central, Mexico/BajaNorte , . / - ; : Punctuation Literal display ‘text’ Quoted text Literal display SELECT TO_CHAR(123456,'9.99EEEE') ,TO_CHAR(123456,'9.9EEEE') FROM dual; TO_CHAR(12 TO_CHAR(1 ---------- --------- 1.23E+05 1.2E+05 SELECT TO_CHAR(-1234.56,'C099G999D99MI','NLS_NUMERIC_CHARACTERS='',.'' NLS_CURRENCY=''DM''NLS_ISO_CURRENCY=''GERMANY''') Balance FROM dual; BALANCE -------------- DEM001.234,56- 其中C 代表使用ISO international currency symbol (format symbol C). For example, the NLS_CURRENCY symbol for U.S. dollars is $, but this symbol is not uniquely American, so the ISO symbol for U.S. dollars is USD. Numeric Cod