博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
得到一个字符串在另一个字符串中出现的次数.sql
阅读量:7087 次
发布时间:2019-06-28

本文共 497 字,大约阅读时间需要 1 分钟。

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_getcharcount]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[f_getcharcount]
GO
--得到一个字符串在另一个字符串中出现的次数
create function f_getcharcount(
@str varchar(8000),
@chr varchar(20)
) returns int
as
begin
declare @re int,@i int
select @re=0,@i=charindex(@chr,@str)+1
while @i>1
    select @re=@re+1
        ,@str=substring(@str,@i,8000)
        ,@i=charindex(@chr,@str)+1
return(@re)
end
go
--调用示例
select dbo.f_getcharcount('aadddbbbbad','ad')

转载地址:http://lbfql.baihongyu.com/

你可能感兴趣的文章
Linux 系统里用户管理
查看>>
上汽集团数据业务部高级总监刘峰:突破瓶颈 激发数据生产力
查看>>
跟我一起数据挖掘(20)——网站日志挖掘
查看>>
HTTPS部署笔记
查看>>
如何优雅的编写 JavaScript 代码
查看>>
MySQL 聚合函数
查看>>
Ubuntu16.10安装Ocata之2:Keystone
查看>>
IGMPv3
查看>>
ZeroMQ(java)之Router/Dealer模式
查看>>
Linux下的文件查找命令
查看>>
数据分析软件SPSS22的授权及汉化
查看>>
TCP/IP协议碎碎念
查看>>
django 将表数据通过API展示到页面上
查看>>
linux用户登录检测发送邮件提醒
查看>>
Gfk报告:中国智能手机统治东南亚市场
查看>>
Exception in thread "main" java.lang.Error: Unresolved compilation problem
查看>>
个人见解 web性能优化
查看>>
中断优先级和中断线程优先级
查看>>
TFS 安装使用GCC4.4版本
查看>>
svn与web 同步更新
查看>>