本文介绍了用于拆分连接字符串的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个关键字表格,我在关键字列中有 商业解决方案+班加罗尔的商业解决方案+迈索尔的商业解决方案 我想用函数分割这些关键字..如何实现这一点。请提供解决方案。I have a keywords table where in keywords column i haveBusiness Solutions + Business Solutions in Bangalore + Business Solutions in MysoreI want to split these keywords using functions.. How to achieve this. Pls provide the solution.推荐答案CREATE FUNCTION [dbo].[String_Tokenizer](@RowData nvarchar(max),@SplitOn nvarchar(5))RETURNS @RtnValue table(Data nvarchar(100))ASBEGINDeclare @Cnt intSet @Cnt = 1While (Charindex(@SplitOn,@RowData)>0)BeginInsert Into @RtnValue (data)SelectData = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))Set @Cnt = @Cnt + 1EndInsert Into @RtnValue (data)Select Data = ltrim(rtrim(@RowData))ReturnEND 上述函数将返回一个临时表。 示例代码:The above function will return a temporary table.Sample code:select * from [dbo].[String_Tokenizer]('Business Solutions + Business Solutions in Bangalore + Business Solutions in Mysore','+') 输出:Output:DataBusiness SolutionsBusiness Solutions in BangaloreBusiness Solutions in Mysore 这篇关于用于拆分连接字符串的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-11 02:55