问题描述
我正在尝试获取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.
推荐答案
针对 字符长度
:
这样做的原因是 char
值用空格填充到声明的长度,因此从本质上讲,它们是声明的长度.
The reasons for this is that char
values are padded with spaces to the declared length, so in essence they are of the declared length.
换句话说,您需要使用:
In other words you need to use:
char_length(trim(trailing from imeprodajalca))
这篇关于在SQL中获取字符串的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!