SQL Server 2005 中的 Len() 与 datalength() [英] Len() vs datalength() in SQL Server 2005
问题描述
最近我在查询中使用 len()
来找出查询的长度时遇到一个问题,len()
没有计算查询中的尾随空格价值.但是 datalength()
也在计算尾随空格.
Recently I faced a issue when using len()
in a query to find out the length of a query, len()
was not counting the trailing spaces in the value. But datalength()
is counting the trailing spaces also.
这是否意味着如果我正在做一些处理值的实际长度的操作,那么我必须使用 dalalength()
而不是 len()
.
Does this means that if I'm doing some operation which deals with the actual length of the value then I have to use dalalength()
over len()
.
例如:如果我需要特定值的值为 10 个字符长度.即如果值是 3 个字符长度,我必须在它后面附加 7 个空格.
ex: If I need the value of a particular value to be is of 10 character length. i.e. If the value is 3 character length I've to append 7 spaces to it.
推荐答案
是的,这正是您必须做的.如果您只想获取不包括空格的字符数,您可以使用 LEN()
函数,而在所有其他情况下为 DATALENGTH()
.
Yes that's exactly what you must do. If you want to just get number of characters excluding blanks you would use LEN()
function, while in all other cases DATALENGTH()
.
即使 LEN()
文档也有信息,要获取表示扩展的字节数,您应该使用 DATALENGTH()
Even LEN()
documentation has an information that to get number of bytes to represent the extension you should use DATALENGTH()
以下是 MSDN 文档的链接:
Here are the links to MSDN docs:
这篇关于SQL Server 2005 中的 Len() 与 datalength()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!