zoukankan      html  css  js  c++  java
  • sqlserver 循环取出字符串按照某个字符分割后的第几个串

    create                 function uf_getStrBySplit(@old_str varchar(8000),@split varchar(50),@pos int) returns varchar(200)
    as
    /*
    功能描述:返回分割后的字符串的第几个字符串
    参数说明:@old_str:原字符串
    @split:分隔符
    @pos:第几个
    */
    begin
    declare @rtn varchar(200),
    @li_p int
    select @rtn=''
    select @old_str=ltrim(rtrim(@old_str))+@split
    select @li_p=0
    while charindex(@split,@old_str)>1
    begin
    select @li_p=@li_p + 1
    if @li_p=@pos
    begin
    select @rtn=left(@old_str,charindex(@split,@old_str) - 1)
    return @rtn
    end
    select @old_str=right(@old_str,len(@old_str) - charindex(@split,@old_str))
    end
    return @rtn
    end
     

    create procedure usp_upd_stadium_stadium(@ids varchar(100))

    as
    /*

    --测试 

    execute usp_upd_stadium_stadium '0001,0002,0003,0004,'
    */
    begin
    declare @i int,
    @cnt int,
    @id varchar(4)
    select @i=0,@cnt=0
    select @cnt=len(replace(@ids,',',',_')) - len(@ids)
    while @i<@cnt
    begin
    select @i=@i+1
    select @id = dbo.uf_getStrBySplit(@ids,',',@i)
    print @id
    end
    end
  • 相关阅读:
    MongoDB高级操作
    MongoDB基本操作
    Python字符串
    Git标签和别名管理
    Git分支管理
    Git远程仓库(github
    Git分布式版本管理工具基本使用方法
    CentOS7防火墙
    CentOS7新特性
    Linux系统初始流程
  • 原文地址:https://www.cnblogs.com/kuailewangzi1212/p/2085054.html
Copyright © 2011-2022 走看看