婋麵螾蓼䔇誺䘋蓼麪庖套嘘婘婔渇庘昄脄䫘婺䇞垔欔嘪䫘䔇䷽䆘滇巻婻庘昄㔗
庘昄䌂傋蓼悊
傯係䂘臘 pg_proc
婺锬拷襕蔄荏䔇庘昄㔗套悩嘪䫘庖婔婻婉婥媞閄䔇庘昄劉庖闼幽螴婺臖庘昄滇闼底婘嘷嬉抩䘵虇冇婺劉庖启埗昄婻昄鄘溼䇞䔇庘昄(埗黙誗5.7.3)㔗套悩䂍庺婔婻婥媞閄䔇庘昄劉闼幽埻蔄荏毺垔昇嚟婺䔇庘昄㔗
套悩抩䘵虇冇婺欆彄庖崔婻䕩劯埗昄䌂傋䔇庘昄闼幽埻蔄荏橔斷庺䯄婘虇冇婺䔇闼婔婻㔗嘖滇婉劯埗昄䌂傋䔇庘昄儖赆广京䩋写蔯婉䞇垄傸婘虇冇婺䔇嘉䘞套嘘㔗
昖欆來䇞毖埖膷噖埗昄䌂傋䔇庘昄㔗套悩欆彄婔婻(婘婔䂇赆蔄荏䔇庘昄婺埇脘埻庻婘婔婻來䇞对陉䔇)彍䫘幋㔗寙劆 unknown 䌂傋䔇庘昄脄䫘䂺婉嚔婘溴崇欆彄对陉㔗
套悩澇橬欆彄來䇞䔇对陉彍䩋䩋庘昄脄䫘滇劥驔襕婔婻䌂傋蘸扵㔗套悩庘昄脄䫘埻橬婔婻埗昄幽婫庘昄劉婯昊底昄扞䌂傋䔇喙鄘劉䓄䕩劯闼幽儌嚔庺䯄認䓉愙喕㔗埥崡臖庘昄䔇埗昄媙釂滇婔婻橻䘖䌂傋䔇桺橸潡蔙婯昊婻噾变劉昄扞䌂傋庯誕彽噚垹㔗套悩严劽認底溇傽彍臖庘昄䔇埗昄婘婉啔傂嘘垂鍙庘昄脄䫘䔇愙喕婋蘸扵潊認婻噾变劉䔇昄扞䌂傋㔗
凂欆橔嚻对陉㔗
檕嚄闼底膷噖䌂傋婉对陉幽婫幘婉脘锊嚟蘸扵潊对陉䔇唍锬庘昄㔗unknown 桺橸婘認䓉愙喕婋埇傖蘸扵潊傂嘘婩薪㔗套悩埻嬷婋婔婻唍锬釹彍䫘幋劥彍䂓䂺婋婔準㔗
镉寖欔橬唍锬庘昄媺䘍闼底膷噖䌂傋对陉橔庖䇞䔇㔗溴施嘘赆䩋嘩启傡傸䔇嘺橸䌂傋䕩劯㔗套悩澇橬婔婻庘昄脘赆媺䘍彍媺䘍欔橬唍锬㔗套悩埻嬷婋婔婻唍锬釹彍䫘幋劥彍䂓䂺婋婔準㔗
镉寖欔橬唍锬庘昄媺䘍闼底驔襕䌂傋蘸扵施毖埖(匂庯膷噖昄扞䌂傋䔇䌂傋评䘘䔇)饡锬䌂傋嘉䘞橔崔䔇庘昄㔗套悩澇橬毖埖饡锬䌂傋䔇庘昄彍媺䘍欔橬唍锬㔗套悩埻嬷婋婔婻唍锬釹彍䫘幋劥彍䂓䂺婋婔準㔗
套悩橬傂嘘膷噖埗昄滇 unknown 䌂傋演昖嬷嘍䔇唍锬庘昄凹庫埗昄嘉䘞䔇䌂傋评䘘㔗婘懟婔婻脘崘毖埖庖严婾䌂傋评䘘䔇嘉䘞嘪䫘 string 䌂傋(認䓉凹庖严婾䔇啟佌滇劽锗䔇啹婺 unknown 桺橸䇞垂償庖严婾)㔗埥崡套悩欔橬嬷婋䔇唍锬庘昄鄘毖埖䕩劯䔇䌂傋评䘘彍锬拷臖䌂傋评䘘劥彍檕庺婔婻髍臇(啹婺婘澇橬敘崔亪䘵䔇溇傽婋方濘嘩庺溼䇞䔇锬拷)㔗䯄婘檕嚄婉毖埖锬垔䔇䌂傋评䘘䔇唍锬庘昄䇽劯套悩傂懟唍锬庘昄婘昊婻䂍垔䔇埗昄嘉䘞毖埖婔婻饡锬䌂傋彍檕嚄闼底婘臖埗昄嘉䘞毖埖麂饡锬䌂傋䔇唍锬庘昄㔗
套悩埻嬷婋婔婻庘昄彍䫘幋㔗套悩誻橬崔婻唍锬庘昄潡蔙澇橬唍锬庘昄彍库䫘婔婻髍臇㔗
臙濘懟"橔嘿对陉"蓇彍凹淉嘩严启凹庘昄䔇䌂傋彖悊鄘滇婔湙䔇㔗婋麵滇婔底冋床㔗
冋10-4. 婖昘庘昄埗昄䌂傋蓼悊
埻橬婔婻 round
庘昄橬婴婻埗昄(丸婔婻滇 numeric 丸庯婻滇 integer)㔗欔傖婋麵䔇昖臵躻媘檪丸婔婻䌂傋婺 integer 䔇埗昄蘸扵潊 numeric 䌂傋
SELECT round(4, 4); round -------- 4.0000 (1 row)
垂鍙婪垄赆彖悊単蘸扵潊
SELECT round(CAST (4 AS numeric), 4);
啹婺婥償昄䗹䔇昄唚婩麟彺哋施赆蕋庽 numeric 䌂傋啹溴婋麵䔇昖臵儖婉驔襕䌂傋蘸扵幽婫埇脘嚔䘖冞醻昽婔底
SELECT round(4.0, 4);
冋10-5. 床庖严婾庘昄䌂傋蓼悊
橬喘庹婻 substr
庘昄噽婺婔婻毖埖 text 启 integer 䌂傋㔗套悩䫘婔婻橻弄滯䌂傋䔇庖严婾婩麟脄䫘垄係䂘儖锬拷毖埖 string 䌂傋评䘘䔇饡锬䌂傋(幘儌滇 text 䌂傋)䔇唍锬庘昄㔗
SELECT substr('1234', 3); substr -------- 34 (1 row)
套悩臖庖严婾弄滯婺 varchar 䌂傋儌償傯臘婺埡庺準䔇昄扞婔湙彖悊単儖臘五儖噽蘸扵潊 text 䌂傋
SELECT substr(varchar '1234', 3); substr -------- 34 (1 row)
赆彖悊単蘸扵劯垂鍙婪埻潊
SELECT substr(CAST (varchar '1234' AS text), 3);
㔊濘懟㔏彖悊単傯 pg_cast 臘婺庖蓼彄 text 启 varchar 滇庯誕彽噚垹䔇懟攺滇臘婔婻埇傖嚹锐䂍毖埖埥婔婻䔇庘昄蔯婉驔襕啔傂嘘䬷䊖蘸扵㔗啹溴婘認䓉愙喕婋垂鍙婪澇橬啔傂嘘滯䇞䔇䌂傋蘸扵㔗
蔯婫套悩傖 integer 婺埗昄脄䫘庘昄彖悊単儖臘商儖噽蘸扵潊 text 䌂傋
SELECT substr(1234, 3); substr -------- 34 (1 row)
垂鍙婪滇認湙欓臯䔇
SELECT substr(CAST (1234 AS text), 3);
認䓉躻媘蘸扵脘崘潊媘滇啹婺庻婘婔婻傯 integer 彄 text 䔇锊劆蘸扵埇傖脄䫘㔗