如何使用 sql 查找字符串中特定字符的出现次数? [英] How can you find the number of occurrences of a particular character in a string using sql?

查看:19
本文介绍了如何使用 sql 查找字符串中特定字符的出现次数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 sql 查找字符串中特定字符的出现次数?

How can you find the number of occurrences of a particular character in a string using sql?

例如:我想找出字母d"在这个字符串中出现的次数.

Example: I want to find the number of times the letter ‘d’ appears in this string.

declare @string varchar(100)
select @string = 'sfdasadhfasjfdlsajflsadsadsdadsa'

推荐答案

给你:

declare @string varchar(100)
select @string = 'sfdasadhfasjfdlsajflsadsadsdadsa'
SELECT LEN(@string) - LEN(REPLACE(@string, 'd', '')) AS D_Count

这篇关于如何使用 sql 查找字符串中特定字符的出现次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆