PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔䆹9. 庘昄启淉嘩严媆誕嬉誕

9.8. 昄扞䌂傋湚嚟寡庘昄

PostgreSQL 湚嚟寡庘昄柊冕婔喖橬昽䔇噖噙䫘庯檪劇䓉昄扞䌂傋蘸扵潊湚嚟寡䔇庖严婾傖埪埉誺準傯湚嚟寡䔇庖严婾蘸扵潊毺垔䔇昄扞䌂傋㔗臘9-20彖庺庖認底庘昄㔗認底庘昄鄘镕冻婔婻噸噌䔇脄䫘幹愇丸婔婻埗昄滇写湚嚟寡䔇唚蔯丸庯婻滇垔幬膷庺潡膷庺湚嚟䔇昇溪㔗

to_timestamp 庘昄幘脘毖埖婔婻 double precision 埗昄檪垄傯 Unix 亻噄蘸扵潊 timestamp with time zoneInteger 䌂傋䔇 Unix 亻噄锊劆婄蘸扵潊庖 double precision

臘9-20. 湚嚟寡庘昄

庘昄誫啂䌂傋柟誄冋床
to_char(timestamp, text)text檪施閘潿蘸扵潊庖严婾to_char(current_timestamp, 'HH12:MI:SS')
to_char(interval, text)text檪施閘閘锫蘸婺庖严婾to_char(interval '15h 2m 12s', 'HH24:MI:SS')
to_char(int, text)text檪昘昄蘸扵潊庖严婾to_char(125, '999')
to_char(double precision, text)text檪垂昄/埯來庥昄蘸扵潊庖严婾to_char(125.8::real, '999D9')
to_char(numeric, text)text檪昄庖蘸扵潊庖严婾to_char(-125.8, '999D99S')
to_date(text, text)date檪庖严婾蘸扵潊斖橘to_date('05 Dec 2000', 'DD Mon YYYY')
to_number(text, text)numeric檪庖严婾蘸扵潊昄庖to_number('12,454.8-', '99G999D9S')
to_timestamp(text, text)timestamp with time zone檪庖严婾蘸扵潊施閘潿to_timestamp('05 Dec 2000', 'DD Mon YYYY')
to_timestamp(double precision)timestamp with time zone檪 UNIX 亻噄蘸扵潊施閘潿to_timestamp(200120400)

婘膷庺昇溪庖严婾麯(凹 to_char 蔯蘔)臖庘昄斟埇傖臖彆婔底䬹垔䔇昇嚟幽婫檪写湚嚟寡䔇昄唚溼䇞婄湚嚟寡潊䕩庫䔇昄扞㔗傂嘘婉匂庯昇溪昇嚟䔇桺橸鄘䞔剘婄锊庖拙蘺㔗劯湙婘婔婻膷噖昇溪庖严婾麯(凹鍴 to_char 崡䔇傂嘘婩薪)昇溪昇嚟湺臖襕昖䩋䔇膷噖昄扞庖严婾幽婫儖婘臖嘉䘞凂欆昄唚㔗

臘9-21滆䴺庖埇傖䫘庯湚嚟寡斖橘启施閘唚䔇昇䬽㔗

臘9-21. 䫘庯斖橘/施閘湚嚟寡䔇昇嚟

昇嚟柟誄
HH婔崷䔇償施昄(01-12)
HH12婔崷䔇償施昄(01-12)
HH24婔崷䔇償施昄(00-23)
MI彖鐘(00-59)
SS䓐(00-59)
MS懆䓐(000-999)
US冞䓐(000000-999999)
SSSS剽崩劯䔇䓐(0-86399)
AMA.M.PMP.M.婪婋剽湺臖(崓喍)
ama.m.pmp.m.婪婋剽湺臖(償喍)
Y,YYY婥锖埙䔇幘(4 启敘崔嘉)
YYYY幘(4 启敘崔嘉)
YYY幘䔇劯婬嘉
YY幘䔇劯婴嘉
Y幘䔇橔劯婔嘉
IYYYISO幘(4 嘉潡敘崔嘉)
IYYISO幘䔇橔劯婬嘉
IYISO幘䔇橔劯婴嘉
IISO幘䔇橔劯婔嘉
BCB.C.ADA.D.亻噄湺臖(崓喍)
bcb.c.ada.d.亻噄湺臖(償喍)
MONTH噘阪崓喍橽傘劉(䷺䍘准噙婺 9 庖严)
Month噘阪晙劽崓償喍橽傘劉(䷺䍘准噙婺 9 庖严)
month噘阪償喍橽傘劉(䷺䍘准噙婺 9 庖严)
MON崓喍䚷喍橽傘劉(3 庖严)
Mon晙劽崓償喍䚷喍橽傘劉(3 庖严)
mon償喍䚷喍橽傘劉(3 庖严)
MM橽傘昄(01-12)
DAY噘阪崓喍斖橘劉(䷺䍘准噙婺 9 庖严)
Day噘阪晙劽崓償喍斖橘劉(䷺䍘准噙婺 9 庖严)
day噘阪償喍斖橘劉(䷺䍘准噙婺 9 庖严)
DY䚷喍崓喍斖橘劉(3 庖严)
Dy䚷喍晙劽崓償喍斖橘劉(3 庖严)
dy䚷喍償喍斖橘劉(3 庖严)
DDD婔幘麯䔇斖(001-366)
DD婔婻橽麯䔇斖(01-31)
D 婔变麯䔇斖(1-7 变斖滇 1)
W婔婻橽麯䔇变昄(1-5)(丸婔变傯臖橽丸婔崷嚔哋)
WW婔幘麯䔇变昄(1-53)(丸婔变傯臖幘䔇丸婔崷嚔哋)
IWISO婔幘麯䔇变昄(丸婔婻滘橘啕婘丸婔变麯)
CC婡亻(2 嘉)(20 婡亻傯 2001-01-01 嚔哋)
J凐䘖斖(躻噸噄嬉 4712 幘 1 橽 1 斖準䔇崷昄)
Q庼庥
RM䘖鷸昄庖䔇橽傘(I-XII I=JAN)(崓喍)
rm䘖鷸昄庖䔇橽傘(I-XII I=JAN)(償喍)
TZ施寺劉(崓喍)
tz施寺劉(償喍)

橬婔底媞閄臉埇傖庫䫘庯昇溪準媞櫹垄傸䔇臯婺㔗懫套FMMonth 儌滇婥五 FM 嬉䚔䔇 Month 昇嚟㔗臘9-22滆䴺庖䫘庯斖橘/施閘湚嚟寡䔇媞閄臉昇嚟㔗

臘9-22. 斖橘/施閘湚嚟寡䔇昇溪昇嚟媞閄臉

媞閄严柟誄冋床
FM 嬉䚔准噙昇嚟(檏彽准噙䷺䍘启镽)FMMonth
TH 劯䚔崓喍釺废昄劯䚔DDTH
th 劯䚔償喍釺废昄劯䚔DDth
FX 嬉䚔啺垔湚嚟噘匔锬釹(蓕䫘濘釂䘖)FX Month DD Day
TM 嬉䚔䪂臏昇嚟(嘺庯 lc_messages 滆䴺橸婄寡䔇斖橘启橽傘劉)TMMonth
SP 劯䚔拚喍昇嚟(誻橻垂䯄)DDSP

斖橘/施閘湚嚟寡䔇䫘濘釂䘖

臘9-23 shows the template patterns available for formatting numeric values

臘9-23. 滆䴺庖埇傖䫘庯昄唚湚嚟寡䔇昇䬽昇嚟㔗

昇嚟柟誄
9婥橬毺垔昄唚嘉昄䔇唚
0婥嬉凚镽䔇唚
. (埖䗹)償昄䗹
, (锖埙)彖䂇(剄)彖锫严
PR儡拸埙喙蘘唚
S婥严埙䔇昄唚(嘪䫘寺嘘螆䘞)
L蘓婕严埙(嘪䫘寺嘘螆䘞)
D償昄䗹(嘪䫘寺嘘螆䘞)
G彖䂇彖锫严(嘪䫘寺嘘螆䘞)
MI婘毺滯䔇嘉䘞䔇蘘埙(套悩昄庖 < 0)
PL婘毺滯䔇嘉䘞䔇溼埙(套悩昄庖 > 0)
SG婘毺滯䔇嘉䘞䔇溼/蘘埙
RN䘖鷸昄庖(膷噖婘 1 启 3999 幋閘)
THth废昄劯䚔
V䓂媘毺垔嘉(償昄)(埗黙濘蓼)
EEEE䓏庥螄昄(儔橻垂䯄)

昄庖湚嚟寡䔇䫘濘釂䘖

臘9-24 滆䴺庖婔底 to_char 庘昄䔇䫘濘㔗

臘9-24. to_char 䴺冋

臘膆嚟䂷悩
to_char(current_timestamp, 'Day, DD  HH12:MI:SS')'Tuesday  , 06  05:39:18'
to_char(current_timestamp, 'FMDay, FMDD  HH12:MI:SS')'Tuesday, 6  05:39:18'
to_char(-0.1, '99.99')'  -.10'
to_char(-0.1, 'FM9.99')'-.1'
to_char(0.1, '0.9')' 0.1'
to_char(12, '9990999.9')'    0012.0'
to_char(12, 'FM9990999.9')'0012.'
to_char(485, '999')' 485'
to_char(-485, '999')'-485'
to_char(485, '9 9 9')' 4 8 5'
to_char(1485, '9,999')' 1,485'
to_char(1485, '9G999')' 1 485'
to_char(148.5, '999.999')' 148.500'
to_char(148.5, 'FM999.999')'148.5'
to_char(148.5, 'FM999.990')'148.500'
to_char(148.5, '999D999')' 148,500'
to_char(3148.5, '9G999D999')' 3 148,500'
to_char(-485, '999S')'485-'
to_char(-485, '999MI')'485-'
to_char(485, '999MI')'485 '
to_char(485, 'FM999MI')'485'
to_char(485, 'PL999')'+485'
to_char(485, 'SG999')'+485'
to_char(-485, 'SG999')'-485'
to_char(-485, '9SG99')'4-85'
to_char(-485, '999PR')'<485>'
to_char(485, 'L999')'DM 485
to_char(485, 'RN')'        CDLXXXV'
to_char(485, 'FMRN')'CDLXXXV'
to_char(5.2, 'FMRN')'V'
to_char(482, '999th')' 482nd'
to_char(485, '"Good number:"999')'Good number: 485'
to_char(485.8, '"Pre:"999" Post:" .999')'Pre: 485 Post: .800'
to_char(12, '99V999')' 12000'
to_char(12.4, '99V999')' 12400'
to_char(12.45, '99V9')' 125'

劯锔饡釕嬉誕
昇嚟对陉婪婔亓施閘/斖橘庘昄启淉嘩严