已知一个字符串  '88+spp/67yi'
通过函数把数字取出来:8867请问用什么函数?

解决方案 »

  1.   

    create table tb(col varchar(20))
    insert into tb values('88+spp/67yi') 
    insert into tb values('88+spp/68yi') 
    go
    create function getnewstr(@oldstr varchar(100)) returns varchar(100)
    as
      begin
        declare @i int
        set @i = 1
        while @i <= len(@oldstr)
        if substring(@oldstr, @i, 1) like('[^0-9]')
           set @oldstr = replace(@oldstr, substring(@oldstr, @i, 1), '')
        else
           set @i = @i +1
        return @oldstr
    end
    goselect col = dbo.getnewstr(col) from tb where col like('%[^0-9]%')drop table tb
    drop function dbo.getnewstr/*
    col                      
    ---------
    8867
    8868(所影响的行数为 2 行)
    */