字符串替换数字

法一:

create function f_str(@str varchar(400))
returns varchar(400)
as
begin
while patindex('%[0-9]%',@str)>0
begin
set @str = stuff( @str, patindex('%[0-9]%',@str) ,1 ,'')
end
return @str
end
go

declare @s varchar(100)
set @s = '3a11n34sH789il010v99l'

select dbo.f_str(@s)
go

drop function f_str

/*

-------------
ansHilvl
(所影响的行数为 1 行)
*/

法二:
declare @Str varchar(100)
set @Str = '333333a11n34sH78123321i10C741h85u21NL0v999999'
select @Str = replace(@Str, num, '') from
(
select 0 num union all
select 1 num union all
select 2 num union all
select 3 num union all
select 4 num union all
select 5 num union all
select 6 num union all
select 7 num union all
select 8 num union all
select 9 num
) a
select @Str

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值