regex 在特定存储过程中使用特定单词的Count匹配项进行搜索

vsmadaxz  于 2023-01-06  发布在  其他
关注(0)|答案(1)|浏览(119)

如何通过下面的代码搜索两个单词来找到两个单词(michael|库尔迪普),

declare @word varchar(128)
set @word = (michael|Kuldeep)

select 
    name, 
    (len(object_definition(object_id)) -  len(replace(object_definition(object_id), @word, ''))) / len (@word) as qty
from 
    sys.procedures
where 
    object_definition(object_id) like '%' + @word + '%' 
    and type = 'P'
    and name = 'MenuDetailsSelect'
order by 
    name

我需要的是使用正则表达式查找两个名称

4xrmg8kj

4xrmg8kj1#

我能够通过使用下面的代码来实现我的目标

declare @word1 varchar(128)
set @word1 = 'Michael'
select name, (len(object_definition(object_id)) -  len(replace(object_definition(object_id), @word1, ''))) / len (@word1) as Michael
from sys.procedures
where object_definition(object_id) like '%'+@word1+'%' and type = 'P'
AND name='MenuDetailsSelect'

declare @word2 varchar(128)
set @word2 = 'Kuldeep'
select name, (len(object_definition(object_id)) -  len(replace(object_definition(object_id), @word2, ''))) / len (@word2) as Raveena
from sys.procedures
where object_definition(object_id) like '%'+@word2+'%' and type = 'P'
AND name='MenuDetailsSelect'

试图让它像在一个查询中一样。

相关问题