postgres中的to_char(number)函数 [英] to_char(number) function in postgres

查看:395
本文介绍了postgres中的to_char(number)函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用to_char()函数将数字显示/转换为字符(长度相同)。

i want to display/convert a number to character (of it's same length) using to_char() function .

在oracle中我可以这样写

In oracle i can write like

SELECT to_char(1234) FROM DUAL

中选择to_char(1234)

但是在postgres中
SELECT to_char(1234)
不起作用。

But in postgres SELECT to_char(1234) is not working.

推荐答案

您需要提供格式掩码。在PostgreSQL中没有默认值:

You need to supply a format mask. In PostgreSQL there is no default:

select to_char(1234, 'FM9999');

如果您不知道数字位数,只需估算最大位数即可。

If you don't know how many digits there are, just estimate the maximum:

select to_char(1234, 'FM999999999999999999');

如果数字较少,则不会有任何副作用。

If the number has less digits, this won't have any side effects.

如果您不需要任何格式(如小数点,千位分隔符),也可以将值强制转换为文本:

If you don't need any formatting (like decimal point, thousands separator) you can also simply cast the value to text:

select 1234::text

这篇关于postgres中的to_char(number)函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆