如何将整数转换为字符串并获取字符串的长度 [英] How to convert integer to string and get length of string

查看:180
本文介绍了如何将整数转换为字符串并获取字符串的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中,有一个字段 last_id ,类型为 integer 。该表包含几行。假设 last_id 的最大值为104050。现在我想知道此整数的 length

In my database there is a field last_id of type integer. The table contains several rows. Let's say the maximum value of last_id is 104050. Now I want to know the length of this integer.

因为这是不可能的,所以我试图将其转换为字符串。

As this is not possible I am trying to convert it into a string.

SELECT to_char(MAX(last_id),'99') FROM xxxx

我希望这会产生type = text的10,但它会返回## type = text。
之后,我将使用 SELECT char_length(to_char(MAX(last_id),'99'))FROM xxx 应该返回2 ...

I would expect this to yield 10 with type = text, but instead it returns ## type = text. Afterwards I would use SELECT char_length(to_char(MAX(last_id),'99')) FROM xxx which should return 2 ...

这里出了什么问题?

推荐答案

发布 整数将值转换为文本

SELECT length(max(last_id)::text) FROM xxx

这篇关于如何将整数转换为字符串并获取字符串的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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