PostgreSQL中有以下格式化函数:

时间:2020-08-04 09:53:18   收藏:0   阅读:92
函数返回类型描述例子
to_char(timestamptext) text 把时间戳转成字符串 to_char(current_timestamp, ‘HH12:MI:SS‘)
to_char(intervaltext) text 把间隔转成字符串 to_char(interval ‘15h 2m 12s‘, ‘HH24:MI:SS‘)
to_char(inttext) text 把整数转成字符串 to_char(125, ‘999‘)
to_char(double precisiontext) text 把实数或双精度转成字符串 to_char(125.8::real, ‘999D9‘)
to_char(numerictext) text 把数字转成字符串 to_char(-125.8, ‘999D99S‘)
to_date(texttext) date 把字符串转成日期 to_date(‘05 Dec 2000‘, ‘DD Mon YYYY‘)
to_number(texttext) numeric 把字符串转成数字 to_number(‘12,454.8-‘, ‘99G999D9S‘)
to_timestamp(texttext) timestamp with time zone 把字符串转成时间戳 to_timestamp(‘05 Dec 2000‘, ‘DD Mon YYYY‘)

用to_number实现,保留数字的小数点后4位?

 

select to_char(字段,‘9999999999.9999‘) x from 表

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!