锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
The following are number examples for the to_char function.
to_char(1210.73, '9999.9') would return '1210.7' to_char(1210.73, '9,999.99') would return '1,210.73' to_char(1210.73, '$9,999.00') would return '$1,210.73' to_char(21, '000099') would return '000021'
The following is a list of valid parameters when the to_char function is used to convert a date to a string. These parameters can be used in many combinations.
Parameter Explanation YEAR Year, spelled out YYYY 4-digit year YYY
YY
YLast 3, 2, or 1 digit(s) of year. IYY
IY
ILast 3, 2, or 1 digit(s) of ISO year. IYYY 4-digit year based on the ISO standard Q Quarter of year (1, 2, 3, 4; JAN-MAR = 1). MM Month (01-12; JAN = 01). MON Abbreviated name of month. MONTH Name of month, padded with blanks to length of 9 characters. RM Roman numeral month (I-XII; JAN = I). WW Week of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year. W Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh. IW Week of year (1-52 or 1-53) based on the ISO standard. D Day of week (1-7). DAY Name of day. DD Day of month (1-31). DDD Day of year (1-366). DY Abbreviated name of day. J Julian day; the number of days since January 1, 4712 BC. HH Hour of day (1-12). HH12 Hour of day (1-12). HH24 Hour of day (0-23). MI Minute (0-59). SS Second (0-59). SSSSS Seconds past midnight (0-86399). FF Fractional seconds.
The following are date examples for the to_char function.
to_char(sysdate, 'yyyy/mm/dd'); would return '2003/07/09' to_char(sysdate, 'Month DD, YYYY'); would return 'July 09, 2003' to_char(sysdate, 'FMMonth DD, YYYY'); would return 'July 9, 2003' to_char(sysdate, 'MON DDth, YYYY'); would return 'JUL 09TH, 2003' to_char(sysdate, 'FMMON DDth, YYYY'); would return 'JUL 9TH, 2003' to_char(sysdate, 'FMMon ddth, YYYY'); would return 'Jul 9th, 2003'
You will notice that in some examples, the format_mask parameter begins with "FM". This means that zeros and blanks are suppressed. This can be seen in the examples below.
to_char(sysdate, 'FMMonth DD, YYYY'); would return 'July 9, 2003' to_char(sysdate, 'FMMON DDth, YYYY'); would return 'JUL 9TH, 2003' to_char(sysdate, 'FMMon ddth, YYYY'); would return 'Jul 9th, 2003'
The zeros have been suppressed so that the day component shows as "9" as opposed to "09".
Oracle鍑芥暟to_char杞寲鏁板瓧鍨嬫寚瀹氬皬鏁扮偣浣嶆暟鐨勭敤娉?/strong>
to_char錛屽嚱鏁板姛鑳斤紝灝辨槸灝嗘暟鍊煎瀷鎴栬呮棩鏈熷瀷杞寲涓哄瓧絎﹀瀷銆?/p>
姣斿鏈綆鍗曠殑搴旂敤錛?/p>
鎺ヤ笅鏉ュ啀鐪嬬湅涓嬮潰錛?/p>
涓婇潰鐨勭粨鏋?'.123' 鍦ㄥぇ澶氭暟鎯呭喌涓嬮兘涓嶆槸鎴戜滑鎯寵鐨勭粨鏋滐紝鎴戜滑鎯寵鐨勫簲璇ユ槸 '0.123'銆?/p>
鎴戜滑鏉ョ湅涓涓媡o_char鍑芥暟鐨勫叿浣撶敤娉曪細
TO_CHAR ( n [, fmt [, 'nlsparam']] )
閫氳繃涓婇潰鐨勪簡瑙o紝鍐嶆煡鐪媐mt鐨勪竴浜涙牸寮忥紝鎴戜滑鍙互鐢ㄤ互涓嬭〃杈懼紡寰楀埌'0.123'鐨勫鹼細
' 0.123'鏄嚭鏉ヤ簡錛屽彲鏄墠闈㈠張澶氫簡涓涓┖鏍箋?/p>
瀵逛簬 100.12 鐨勫煎嵈鏄?#####錛屼互鍙?1.12'鐨勫煎彉鎴愪簡 '1.120'銆?/p>
鎴戜滑閲嶆柊紜畾涓涓柊鐨勯渶姹傦細
1銆佸幓絀烘牸
2銆佸皬鏁扮偣鏈澶?浣嶏紝鏈灝戜繚鐣?浣嶃?/p>
1--->'1.00'錛?.1--->'1.00'錛?.12-->'1.12'錛?.1234--->'1.1234'錛?/p>
1.12345--->'1.1235'
鏈緇堝疄鐜板涓嬶細
PLSQL灝忕粡楠屼竴銆?Oracle鐨則o_char()鍑芥暟鍔熻兘寰堝己澶т絾鏄湪鐢ㄥ畠鏍煎紡鍖栨暟鍊煎瀷鏁版嵁鏃跺簲璇ヨ娉ㄦ剰浠ヤ笅鍑犻」銆傚鏋滄槸灝忔暟濡傦細0.23榪欐牱鐨勬暟鎹粡榪噒o_char鍚庡啀鏄劇ず浼氬彉涓?23錛屽鏋滀綘涓轟簡璁╁畠鏄劇ず鍑哄師鏉ョ殑0.23鐨勮瘽灝卞緱鐢═o_char(瑕佹牸寮忓寲鐨勬暟鍊?’0.999’)淇濈暀涓変釜灝忔暟錛屽茍鏄劇ず浣嗚繖閲屽氨瑕佹敞鎰忎簡銆備粬涓轟綘鎴彇灝忔暟鐨勬椂鍊欐槸鍥涜垗浜斿叆浜嗐傛墍浠ュ鏋滄槸瑕佹眰鎴帀灝忔暟鑰屼笉鍥涜垗浜斿叆鐨勮瘽灝卞簲璇ヨ嚜宸卞啓涓嚱鏁版埅涓嬪幓鍚庡啀瑙勬牸鍖栥備互淇濊瘉瀹冧笉鍥涜垗浜斿叆銆?
浜屻?To_char(1.9999,’FM90.0999’)榪欎釜鍑芥暟瑙勬牸鍖栨椂90.0999鐨勫惈涔夋槸鏈?鐨勫湴鏂瑰鏋滄湁鏁板瓧灝辨樉紺哄鏋滄病鏈夋暟瀛楀氨涓嶆樉紺猴紝鏈?鐨勫湴鏂瑰湪娌℃湁鏁板瓧鐨勬椂鍊欎篃浼氭湁錛愭潵鍗犱綅.浣嗚繖鏍峰仛涔熸湁涓涓緢澶х殑緙虹偣,灝辨槸濡傛灉鏄暣鏁版椂瀹冧篃浠嶇劧浼氭樉紺?#8221;.”,涓嶈灝忕灖榪欎釜鐐?涓鑸潵璁查〉闈笂瑕佹樉紺虹殑璇濊繖涓偣灝辨槸澶氫綑鐨?涔熺粰鎴戜滑閫犳垚浜嗕笉灝忕殑楹葷儲.榪樿鑷繁鍐嶅啓鍑芥暟鏉ユ妸榪欎釜灝忕偣鎼炲畾.
涓夈?瀵逛簬鏃ユ湡鍨嬬殑Oracle鍊掓椂鎻愪緵浜嗕竴涓ソ鐨勫鐞嗘柟娉?鍙互鎶婃棩鏈熷仛鎴愭暟鍊煎瀷鐨?鐒跺悗鍐峊o_char灝辮兘鏄劇ず鍑轟綘鎵闇瑕佺殑綾誨瀷浜?
鍥涖?鍦ㄤ嬌鐢╯elect into鏃朵竴瀹氳娉ㄦ剰,榪欑鏂規(guī)硶浣犱竴瀹氳紜鑲畾浼氭湁鏁版嵁琚煡鍑烘椂鎵嶈兘浣跨敤.濡傛灉鏌ヨ緇撴灉涓虹┖鏃朵細瀵艱嚧鎶ラ敊.榪樻湁涓縐嶆儏鍐墊槸鏌ュ嚭鏉ョ殑鏁版嵁鏄鏉′篃浼氭姤閿?鎵浠ュ簲璇ュ敖閲忎究瀹滄父鏍囨潵鍋?浼氬噺灝戦敊璇駭鐢熺殑鏈虹巼.
浜斻?榪樻湁娉ㄦ剰涓鐐箁ownum涓嶆敮鎸佹帓搴?灝辨槸璇翠綘鎯崇敤榪欎釜鏉ユ帶鍒惰鏁扮殑璇濆氨浼氬彂鐜頒粬娌℃湁鎸変綘鎸囧畾鐨勬帓搴忔柟寮忔樉紺?,榪欐槸涓涓緢闅懼姙鐨勪簨.鑰屼笖濡傛灉浣犵敤rownum=2榪欐牱鐨勮鍙ユ潵杈撳嚭絎簩琛岀殑璇濅篃鏄涓嶉氱殑. 鍏?鏈鎭跺績鐨勪竴鐐規(guī)槸Oracle瀵筺ull鐨勫垽鏂彉鎬佸埌鏋佺偣.濡傛灉浣犺鏌愪釜鍙橀噺 aa=null瀹冩槸鍒ゆ柇涓嶅嚭鏉ョ殑.灝界aa鐨勭‘鏄┖.鍗充嬌鍦ㄩ夋嫨鏉′歡閲屼篃鏄垽鏂笉鍑烘潵鐨?涓嶇煡閬撲負浠涔?鍙ソ鐢╪vl()榪欎釜鍑芥暟鏉ュ垽鏂簡.鍦ㄦ潯浠朵箣澶栧彲浠ョ敤 aa is null 鏉ュ垽鏂?
鍏?琛ュ厖涓鐐?灝辨槸鍦ㄥ啓瀛樺偍榪囩▼鏃惰娉ㄦ剰鍙傛暟鍚嶄笉鑳戒笌鏁版嵁搴撳瓧孌靛悕鐩稿悓.鍚﹀垯Oracle浼氭妸榪欎釜鍙傛暟鍚嶇湅鎴愭槸瀛楁鍚嶇殑,鍗充嬌浣犵敤琛ㄧ殑鍒悕鍖哄垎涔熶笉琛?鎵浠ヨ搗鍙傛暟鍚嶇殑鏃跺欎竴瀹氳娉ㄦ剰榪欑偣.浜?