TO_CHAR Function With Date Date Format Model Elements YYYY FULL year innumbers YEAR year spelled out MM2-digit value for month MONTH Full name ofthe month MONName ofmonth,three-letter abbreviation RMRuman numeral month DY3-letter abbreviation ofthe day ofthe week DAYFull name ofthe day SCC entury ;Sprefixes BCdate with - Years indates YYYY orSYYYY Year ;Sprefixes BCdate with - YYY orYYorYLast 3,2,1 digit(s) ofyear Y,YYY Year ma inthis position IYYY orIYY orIYorI4,3,2 or1digit year based onthe ISO standard SYEAR orYEAR year spelled out;S prefixes BCdate with - BCorADBC/AD indicator . . BC/AD indicator with periods QQuarter ofyear WWorWWeek ofthe year ormonth DDD orDDorDDay ofyear,month,week JJulian day;the number ofdays since 31december 4713 BC AMorPMMeridian indicator . . Meridian indicator with periods HHorHH12 orHH24 Hour ofday orhour(12) orhour(24) MIMinute(0-59) SSSecond(0-59) SSSSS Seconds past midnight(0-86399) THOrdinal Number SPSpelled-out number THSP orSPTH Spelled-out Ordinal number /.,Punctuation isreproduced inthe result "of the" Quoted String isreproduced inthe result *: fm 前缀用来去掉 0 如: Select to_char(to_date( '2007-10-05' , 'yyyy-mm-dd' ), 'fmdd' ) From dual; 结果为: 5 Select to_char(to_date( '2007-10-05' , 'yyyy-mm-dd' ), 'dd' ) From dual; 结果为: 05 TO_CHAR Function With Numbers 例: Select to_char( , '' ) From dual; 结果: .99 ( fm去掉左边空格) Select to_char( , 'fm99 0 .99' ) From dual; 结果: 例: T o_char 和 to_date 组合用法 to_char 用于日期转换成字符串时, fm 去掉前导 0,如果格式穿里边重复使用 fm 会发生什么事情? 请看: SQL> select to_char(sysdate,'yy-mm-dd') from dual; TO_CHAR(SYSDATE,'YY-MM-DD') --------------------------- 08-07-16 SQL> select to_char(sysdate,'fmyy-mm-dd') from dual; TO_CHAR(SYSDATE,'FMYY-MM-DD') ----------------------------- 8-7-16 SQL> select to_char(sysdate,'yy-fmmm-dd') from dual; TO_CHAR(SYSDATE,'YY-FMMM-DD') ----------------------------- 08-7-16 SQL> select to_char(sysdate,'fmyy-fmmm-dd') from dual; TO_CHAR(SYSDATE,'FMYY-FMMM-DD' ------------------
to_char 来自淘豆网m.daumloan.com转载请标明出处.