我正在寻找一个RegExp来查找Server和正则表达式(RegExp)中整个单词中的重复字符。例如:
"AAUGUST" match (AA)
"ANDREA" don't match (are 2 vowels "A", buit are separated)
"ELEEPHANT" match (EE)我试着:
SELECT field1
FROM exampleTable
WHERE field1 like '%([A-Z]){2}%'但不起作用。
我请求你的帮助。
谢谢!
发布于 2017-06-21 03:28:54
您不能按照您的要求使用T的LIKE。
最好的选择是考虑使用公共语言运行时(CLR),但也可以使用标量值函数来实现(尽管痛苦地缓慢地使用),如下所示:
create function dbo.ContainsRepeatingAlphaChars(@str nvarchar(max)) returns bit
as begin
declare @p int, -- the position we're looking at
@c char(1) -- the previous char
if @str is null or len(@str) < 2 return 0;
select @c = substring(@str, 1, 1), @p = 1;
while (1=1) begin
set @p = @p + 1; -- move position pointer ahead
if @p > len(@str) return 0; -- if we're at the end of the string and haven't already exited, we haven't found a match
if @c like '[A-Z]' and @c = substring(@str, @p, 1) return 1; -- if last char is A-Z and matches the current char then return "found!"
set @c = substring(@str, @p, 1); -- Get next char
end
return 0; -- this will never be hit but stops SQL Server complaining that not all paths return a value
end
GO
-- Example usage:
SELECT field1
FROM exampleTable
WHERE dbo.ContainsRepeatingAlphaChars(field1) = 1我说过会很慢吗?不要在大桌子上用这个。去CLR吧。
https://stackoverflow.com/questions/44664311
复制相似问题