LTRIM和RTRIM究竟修剪了哪些字符?

时间:2016-02-06 18:46:37

标签: sql-server tsql

LTRIMRTRIM are documented to trim "blanks"。考虑了哪些字符"空白"到底是什么?

1 个答案:

答案 0 :(得分:5)

好问题。尽管Unicode中定义了许多whitespace个字符,但只删除了一个空格(0x0020):

with Characters as (
  select NChar( 0 ) as Character
  union all
  select NChar( Unicode( Character ) + 1 )
    from Characters
    where Unicode( Character ) < 65535 ),
  CharacterMap as (
  select Unicode( Character ) as [UnicodePoint], Character,
    1 - Len( LTrim( Character ) ) as [Whitespace]
    from Characters )
  select UnicodePoint, Character, Whitespace
    from CharacterMap
    where Whitespace = 1
    option ( MaxRecursion 0 );

(这同样适用于RTrim。)