在SQL中获取字符串的长度 [英] Getting the length of a string in SQL
问题描述
我正在尝试获取SQL中字符串的长度(使用Firebird 2.x +版本).每当我选择一个字符串的长度时,它都会给我该字符串的实际分配的最大长度,而不是获取记录中记录了多少个字符的长度,如您在此处看到的:
I'm trying to get the length of a string in SQL (using Firebird version 2.x+). Whenever I select the length of a string it gives me the actual assigned maximum length of that string as opposed to getting the length of how many of the characters are taken in a record, as you can see here:
您可以想象,这对我没有帮助,因为我无法按长度排序,因为我试图按已分配了恒定长度的属性进行排序.
as you can imagine, this does not help me, as I can't order by the length, since I'm trying to order by an attribute that has a constant length assigned.
我将如何实现自己想要实现的目标?那就是:获取一个字符串中包含多少个字符的长度.
How would I achieve what I am trying to achieve? That is: getting the length of how many characters are taken in a string.
推荐答案
针对 这样做的原因是 The reasons for this is that 换句话说,您需要使用: In other words you need to use: 这篇关于在SQL中获取字符串的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!注释
CHAR
的参数,此函数返回形式的字符串长度(即,字段或变量的声明长度).如果要获得逻辑"长度,而不计算尾随空格,请右键-
Notes
CHAR
, this function returns the formal string length (i.e. the declared length of a field or variable). If you want to obtain the "logical" length, not counting the trailing spaces, right-TRIM
the argument before passing it to CHAR[ACTER]_LENGTH
. char
值用空格填充到声明的长度,因此从本质上讲,它们是声明的长度.char
values are padded with spaces to the declared length, so in essence they are of the declared length.char_length(trim(trailing from imeprodajalca))