2个回答
展开全部
我来回答吧: 下列sql语句我测试过, sql server版的,要是mysql需要转换下。可以Hi我
建立函数
create function myfn_GetInt(@str varchar(50))
returns varchar(50)
as
begin
if @str = ''
return ''
declare @r varchar(50), @index int, @temp varchar(2)
set @r = ''
set @index = len(@str)
set @temp = ''
while @index > 0
begin
set @temp = substring(@str,@index,1)
if '1234567890' not like '%'+@temp+'%'
begin
if @r <> ''
break
end
else
set @r = @r + @temp
set @index = @index - 1
end
set @r = REVERSE(@r)
return @r
end
执行函数,显示结果为 08
select dbo.myfn_GetInt('我出生于1979年08月十六日')
建立函数
create function myfn_GetInt(@str varchar(50))
returns varchar(50)
as
begin
if @str = ''
return ''
declare @r varchar(50), @index int, @temp varchar(2)
set @r = ''
set @index = len(@str)
set @temp = ''
while @index > 0
begin
set @temp = substring(@str,@index,1)
if '1234567890' not like '%'+@temp+'%'
begin
if @r <> ''
break
end
else
set @r = @r + @temp
set @index = @index - 1
end
set @r = REVERSE(@r)
return @r
end
执行函数,显示结果为 08
select dbo.myfn_GetInt('我出生于1979年08月十六日')
展开全部
--测试数据:
declare @t table(s varchar(366))
insert into @t
select
'012月'
union all select
'06月'
--以下为查询语句,实际应用把表名和字段名改为实际即可
select substring(s,len(s) - PATINDEX('%[0-9]%',REVERSE(s)),2) as 结果
from @t
where PATINDEX('%[0-9]%',REVERSE(s)) > 0 and isnumeric(substring(s,len(s) - PATINDEX('%[0-9]%',REVERSE(s)),2)) = 1
declare @t table(s varchar(366))
insert into @t
select
'012月'
union all select
'06月'
--以下为查询语句,实际应用把表名和字段名改为实际即可
select substring(s,len(s) - PATINDEX('%[0-9]%',REVERSE(s)),2) as 结果
from @t
where PATINDEX('%[0-9]%',REVERSE(s)) > 0 and isnumeric(substring(s,len(s) - PATINDEX('%[0-9]%',REVERSE(s)),2)) = 1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询