sql智能分割字符函数
来源:互联网 发布:关于大数据例子分析 编辑:程序博客网 时间:2024/05/21 07:58
- SQL code
- FUNCTION fn_Split(@sText varchar(8000), @sDelim varchar(20) = ' ')RETURNS @retArray TABLE (idx smallint Primary Key, value varchar(8000))ASBEGINDECLARE @idx smallint,@value varchar(8000),@bcontinue bit,@iStrike smallint,@iDelimlength tinyintIF @sDelim = 'Space'BEGINSET @sDelim = ' 'ENDSET @idx = 0SET @sText = LTrim(RTrim(@sText))SET @iDelimlength = DATALENGTH(@sDelim)SET @bcontinue = 1IF NOT ((@iDelimlength = 0) or (@sDelim = 'Empty'))BEGINWHILE @bcontinue = 1 BEGIN--If you can find the delimiter in the text, retrieve the first element and--insert it with its index into the return table. IF CHARINDEX(@sDelim, @sText)>0 BEGIN SET @value = SUBSTRING(@sText,1, CHARINDEX(@sDelim,@sText)-1) BEGIN INSERT @retArray (idx, value) VALUES (@idx, @value) END --Trim the element and its delimiter from the front of the string. --Increment the index and loop.SET @iStrike = DATALENGTH(@value) + @iDelimlength SET @idx = @idx + 1 SET @sText = LTrim(Right(@sText,DATALENGTH(@sText) - @iStrike)) END ELSE BEGIN--If you can抰 find the delimiter in the text, @sText is the last value in--@retArray.SET @value = @sText BEGIN INSERT @retArray (idx, value) VALUES (@idx, @value) END --Exit the WHILE loop.SET @bcontinue = 0 END ENDENDELSEBEGINWHILE @bcontinue=1 BEGIN --If the delimiter is an empty string, check for remaining text --instead of a delimiter. Insert the first character into the --retArray table. Trim the character from the front of the string.--Increment the index and loop. IF DATALENGTH(@sText)>1 BEGIN SET @value = SUBSTRING(@sText,1,1) BEGIN INSERT @retArray (idx, value) VALUES (@idx, @value) END SET @idx = @idx+1 SET @sText = SUBSTRING(@sText,2,DATALENGTH(@sText)-1) END ELSE BEGIN --One character remains. --Insert the character, and exit the WHILE loop. INSERT @retArray (idx, value) VALUES (@idx, @sText) SET @bcontinue = 0 ENDENDENDRETURNEND下面是调用示例:declare @no char(100)set @no='abc,cdesefd,efddc,mgns,aa'select * from fn_Split(@no,',')智能分割字符函数
能把些字分割为这样
嫦娥一号成功发射成功
分割为这样:
0 嫦
1 娥
2 一
3 号
4 成
5 功
6 发
7 射
8 成
9 功
- sql智能分割字符函数
- SQL实现split函数,自定义分割字符,自定义取出第几个分割字符前的字符串
- Oracle SQL 字符分割
- SQL Server 字符分割
- 字符分割函数.
- 字符的分割函数
- CString 字符分割 函数
- 自定义字符分割函数
- SQL 字符串分割函数
- SQL分割字符串函数
- 分割函数sql
- SQL分割字符串函数
- SQL 字串分割函数
- SQL分割字符串函数
- SQL 分割函数
- string 根据字符分割函数
- 分割字符串的sql函数
- SQL 字符串分割函数 split
- FMS做成的客户端动画同步(网游基础)
- 我的技术博客终于找到一个好地方重新开张了~
- .net分页显示空行
- js实现拖拽
- Size Balance Tree和Treap的ADT接口和实现
- sql智能分割字符函数
- 一千年前的中国和世界
- 求助
- CSDN剪影产品页
- 关于WEB页的局部打印问题:
- 一个新程序员的感想
- GridView产生纵向横向的滚动条
- 注册表工具大餐
- asp.net 2.0 用户管理功能结构