Several SQL programmers want to delimit string split in SQL server. But sometimes, programmers may get confused as to how you can do it. So, in this article, you can learn a few methods to SQL split string by delimiter, which are easy to understand. Read and follow these steps carefully to SQL delimiter split successfully on your SQL server.
4 Ways to Split String by Delimiter in SQL
Կա չորս եղանակ with which you can split a delimited string value. You can use any of the methods with the respective function to achieve the desired output code in the SQL server. Let’s get started!
Method 1: Standard SQL Split String
It is one of the easiest methods you can attempt to split a delimited string. In this method, we have to use the SPLIT() function. This function takes string and delimiter as the arguments. And this string is then split based on the specified delimiter.
շարահյուսություն:
SPLIT(VALUE[, delimiter])
1. Based on the comma (,) delimiter, this function will split the string value by default. But the condition is that you should specify the target delimiter for bytes.
Օրինակ:
SELECT SPLIT('1,2,3,4,5,6,7', ',') AS arr;
Արտադրողականություն:
ժամանել "[1,2,3,4,5,6,7]"
2. If an empty delimiter is specified, the function will return a UTF-8 characters array from the string value. We are splitting the string with the տարածություն which acts as the delimiter այս դեպքում.
Օրինակ: (Array of strings)
SELECT SPLIT('p q r s t u v', ' ') AS arr;
Արտադրողականություն:
ժամանել "[p,q,r,s,t,u,v]"
3. Also, if you run an դատարկ տող, the function will give an output with the empty array.
Օրինակ:
SELECT SPLIT('', '') AS arr;
Արտադրողականություն:
ժամանել []
Կարդացեք նաեւ: Fix Command Failed With Error Code 1 Python Egg Info
Method 2: SQL Server Split String
Դուք կարող եք օգտագործել այն STRING_SPLIT() function in the SQL server to split a delimited string.
Շարահյուսություն:
STRING_SPLIT (string , delimiter )
Օրինակ:
SELECT VALUE - ԻՑ STRING_SPLIT('m,n,o,p,q,r', ',');
Արտադրողականություն:
VALUE -------------------- m n o p q r
Method 3: PostgreSQL Split String
Օգնությամբ SPLIT_PART() function, you can split any string in SQL. This PostgreSQL split string function takes a string to split and a delimiter to use. Also, it returns the part of the string as specified.
Նշում: The position parameter should be a դրական ամբողջ թիվ which should start at 1.
Շարահյուսություն:
SPLIT_PART(string, delimiter, position)
Օրինակ:
select split_part(‘h,e,l,l,o’, ‘,’, 3);
Արտադրողականություն:
split_part l
Կարդացեք նաեւ: How to Enable or Disable JavaScript in your Browser
Method 4: MySQL Split String
Է MySQL Split String method, we can use the SUBSTRING_INDEX() function to split a delimited string in SQL. Now, this function takes the string, delimiter, and string count as the arguments and returns the number of strings depending upon the count split by the provided delimiter.
Շարահյուսություն:
SUBSTRING_INDEX(string, delimiter, count)
Օրինակ:
SELECT SUBSTRING_INDEX('q,w,e,r,t,y', ',', 6);
Արտադրողականություն:
q,w,e,r,t,y
Լավագույն վաճառք:
So now, we hope you have understood the mentioned 4 եղանակներ SQL split string by delimiter with the syntax to your aid. You can let us know any queries about this article or suggestions about any other topic you want us to make an article on. Drop them in the comments section below for us to know.