gpt4 book ai didi

sql - 替换 T-SQL 中的 Unicode 字符

转载 作者:行者123 更新时间:2023-12-02 22:35:25 24 4
gpt4 key购买 nike

如何仅替换字符串的最后一个字符:

select REPLACE('this is the news with a þ', 'þ', '__')

我得到的结果是:

__is 是 __e 新闻 __ a __

编辑服务器和数据库的排序规则为Latin1_General_CI_AS

我运行的实际查询是REPLACE(note, 'þ', ''),其中note是一个ntext列。关键是要去掉刺字符,因为该字符稍后会在该过程中用作列分隔符。 (请不要建议更改分隔符,考虑到它的使用范围,这种情况是不会发生的!)

我尝试使用 N 前缀,甚至使用测试选择语句,结果如下:

Still broken!

最佳答案

þ 字符(扩展 ASCII { 通过 ISO-8859-1 和 ANSI 代码页 1252 } & UNICODE 值为 254)被称为“thorn”,在某些语言中直接等同于 :

  • 有关该角色的技术信息:http://unicode-table.com/en/00FE/

  • 该字符和排序规则的说明:http://userguide.icu-project.org/collation/customization 。在页面(通常是 Control-F)中搜索“复杂剪裁示例”,您将看到以下内容:

    The letter 'þ' (THORN) is normally treated by UCA/root collation as a separate letter that has primary-level sorting after 'z'. However, in Swedish and some other Scandinavian languages, 'þ' and 'Þ' should be treated as just a tertiary-level difference from the letters "th" and "TH" respectively.

如果您不希望 þ 等于 th,则强制执行二进制排序规则,如下所示:

SELECT REPLACE(N'this is the news with a þ' COLLATE Latin1_General_100_BIN2,
N'þ', N'__');

返回:

this is the news with a __
<小时/>

有关使用排序规则、Unicode、编码等的更多信息,请访问:Collations Info

关于sql - 替换 T-SQL 中的 Unicode 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29012872/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com