在 SQL Server 2008 和 2014 之间使用 XQuery 函数 substring() 有什么区别?
what's the difference between use of XQuery functions substring() between SQL Server 2008 and 2014?
根据 Microsoft 新 SQL 服务器版本 2014,substring
function 在 XQuery
中的使用有所不同:
If the compatibility level is 110 or later, each surrogate pair is counted as a single character. For earlier compatibility levels, they are counted as two characters.
这里的"surrogate pair"是什么意思?请提供一些示例来解释 SQL 服务器中的此新功能。
我希望它指的是 UTF-16 代理项对,其中两个代码单元(在 0xD800 到 0xDFFF 范围内)编码 U+10000 到 U+10FFFF 范围内的单个字符。
我将你引用的语句解释为早期版本将每个代码点解释为单个字符,即使它实际上是单个字符的一半。
使用 Wikipedia 中的示例,</code> (<code>U+10437
) 被编码为两个代码点 D801 DC37。较旧的服务器会将每个代码点视为一个独立的字符,substring
甚至可能将两者分开。
举个具体的例子,考虑在"abcd"
中找到第三个字符:
substring("abcd", 2, 1)
较旧的服务器将 </code> 视为两个单独的字符,因此结果为 <code>"a"
。 (D801DC37ab cd).
较新的服务器将</code>识别为一个不可分割的字符,结果是<code>"b"
。 (abcd).
根据 Microsoft 新 SQL 服务器版本 2014,substring
function 在 XQuery
中的使用有所不同:
If the compatibility level is 110 or later, each surrogate pair is counted as a single character. For earlier compatibility levels, they are counted as two characters.
这里的"surrogate pair"是什么意思?请提供一些示例来解释 SQL 服务器中的此新功能。
我希望它指的是 UTF-16 代理项对,其中两个代码单元(在 0xD800 到 0xDFFF 范围内)编码 U+10000 到 U+10FFFF 范围内的单个字符。
我将你引用的语句解释为早期版本将每个代码点解释为单个字符,即使它实际上是单个字符的一半。
使用 Wikipedia 中的示例,</code> (<code>U+10437
) 被编码为两个代码点 D801 DC37。较旧的服务器会将每个代码点视为一个独立的字符,substring
甚至可能将两者分开。
举个具体的例子,考虑在"abcd"
中找到第三个字符:
substring("abcd", 2, 1)
较旧的服务器将
</code> 视为两个单独的字符,因此结果为 <code>"a"
。 (D801DC37ab cd).较新的服务器将
</code>识别为一个不可分割的字符,结果是<code>"b"
。 (abcd).