我的表中有字符串值,其中包括希伯来语字符(或本例中的任何R-T-L语言)和英语字符(或数字)。
问题是英文字符颠倒过来了,看起来像:בדיקה123456 esrever sti fI kcehC。
数字和英文字符是颠倒的,希伯来语的是好的。
如何使用内置的SQL函数来识别英语子字符串(和数字)并反转它,同时保持其他RTL字符的顺序?
我在下面的链接中读到了这个问题的答案:Reverse characters in string with mixed Left-to-right and Right-to-left languages using SQL?
解决方案:
DECLARE @sourceString NVARCHAR(100) = N'123456 בדיקה esrever sti fI kcehC';
DECLARE @reversedString NVARCHAR(4000) = nchar(8237) + REVERSE(@sourceString) + nchar(8236)
SELECT @reversedString;我的问题:当我尝试使用这个选项构建查询时,它不起作用,例如:
select count(*) from table where nchar(8237) + REVERSE(column) + nchar(8236) = N'Check If its reverse הקידב 654321'我怎么才能修复它?
发布于 2018-01-08 19:05:45
在SQL-Server中,RTL字符串的行为,特别是混合使用时,有时真的很奇怪。
我不知道您到底想实现什么,但这至少会给您提供unicode代码点:
DECLARE @source NVARCHAR(100)=N'123456 בדיקה esrever sti fI kcehC';
WITH cte AS
(
SELECT 1 AS pos
,UNICODE(SUBSTRING(@source,1,1)) AS CodeAtPosition
UNION ALL
SELECT cte.pos+1
,UNICODE(SUBSTRING(@source,cte.pos+1,1))
FROM cte
WHERE pos<LEN(@source)
)
SELECT *
FROM cte希伯来语字符来自更高的范围:
pos CodeAtPosition
1 49
2 50
3 51
4 52
5 53
6 54
7 32
8 1489 <-- starting here
9 1491
10 1497
11 1511
12 1492 <-- ending here
13 32
14 101
...more rows有用的答案:https://stackoverflow.com/a/29821207/5089204
关于双向文本的一些东西:https://www.w3.org/TR/WCAG20-TECHS/H34.html
https://stackoverflow.com/questions/48147690
复制相似问题