In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
| | 0 | SELECT STATEMENT | | 107 | 2782 | 3 (34) | 00:00:01 | | 1 | PX COORDINATOR | | |
© 2024 shulou.com SLNews company. All rights reserved.