PostgreSQL - 将字符串转换为 ASCII 整数
PostgreSQL - Convert string to ASCII integer
如何在 PostgreSQL 中获取字符串的 ASCII 值作为 int?
例如:字符串S06.6X9A
目前,我正在使用 ASCII 函数,但它 returns 只是给定字符串的第一个字符。
使用 string_to_array('S06.6X9A', null)
将字符串拆分为 text[]
个单独的字符。然后 unnest
将 text[]
变成 table。然后在 from
子句中使用它,并在每一行上使用 运行 ascii()
。
select ascii(char)
from (
select unnest( string_to_array('S06.6X9A', null) )
) as chars(char);
ascii
-------
83
48
54
46
54
88
57
65
比 Schwern 的答案更简单:
SELECT ascii( unnest( string_to_array('S06.6X9A', NULL) ) )
如何在 PostgreSQL 中获取字符串的 ASCII 值作为 int?
例如:字符串S06.6X9A
目前,我正在使用 ASCII 函数,但它 returns 只是给定字符串的第一个字符。
使用 string_to_array('S06.6X9A', null)
将字符串拆分为 text[]
个单独的字符。然后 unnest
将 text[]
变成 table。然后在 from
子句中使用它,并在每一行上使用 运行 ascii()
。
select ascii(char)
from (
select unnest( string_to_array('S06.6X9A', null) )
) as chars(char);
ascii
-------
83
48
54
46
54
88
57
65
比 Schwern 的答案更简单:
SELECT ascii( unnest( string_to_array('S06.6X9A', NULL) ) )