In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
SQL how to decompose strings according to the specified delimiter, for this problem, this article details the corresponding analysis and solution, hoping to help more small partners who want to solve this problem find a simpler and easier way.
If you have a string eg: "sun,star,moon,clouds" and you want to break this string into elements [sun] [star] [moon] [clouds] in MS SQL according to the given delimiter ',' how do you do that? To do this, create a Function with the following code: Copy the code with the following code: CREATE FUNCTION [dbo]. [Split_StrByDelimiter](@String VARCHAR(8000), @Delimiter CHAR(1)) RETURNS @temptable TABLE (items VARCHAR(8000)) AS BEGIN DECLARE @idx INT DECLARE @slice VARCHAR(8000) SELECT @idx = 1 IF len(@String)0) INSERT INTO @temptable(Items) VALUES(@slice) SET @String = RIGHT(@String,len(@String) - @idx) IF len(@String) = 0 break END RETURN END
Examples: If SELECT * FROM dbo.Split_StrByDelimiter ('sun,star,moon,clouds',',') returns sun star moon clouds in the above code deformation, returns how many elements copied code is as follows: CREATE FUNCTION [dbo]. [GetCount_Split_StrByDelimiter](@String VARCHAR(8000), @Delimiter CHAR(1)) RETURNS INT AS BEGIN DECLARE @temptable TABLE (items VARCHAR(8000)) DECLARE @SplitCount INT DECLARE @idx INT DECLARE @slice VARCHAR(8000) SELECT @idx = 1 IF len(@String)0) INSERT INTO @temptable(Items) VALUES(@slice) SET @String = RIGHT(@String,len(@String) - @idx) IF len(@String) = 0 break END SET @SplitCount=(SELECT COUNT(*) FROM @temptable) RETURN @SplitCount END
Example SELECT dbo.GetCount_Split_StrByMinimiter ('sun,star,moon, clouds',',') Returns 4
About SQL how to break down the string according to the specified delimiter questions to share here, I hope the above content can be of some help to everyone, if you still have a lot of doubts not solved, you can pay attention to the industry information channel to learn more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.