In this post, I am providing one function to split string by using different type of delimiters and position in MySQL.
I have created this function because splitting a string is a very common requirement for all MySQL Database Developer.
I have created this function in such a way that you guys can pass any type of delimiter and split your string, but you also require to pass position to get exact value.
I have also created a similar kind of split function for SQL Server.
You can visit this article here:
For example, we have one column EmployeeName and it contains both Firstname and Lastname which is sperated by space. I require to create two column EmployeeFirstName and EmployeeLastName.
Below is a function and full demonstration of this:
First, Create a user defined function:
CREATE FUNCTION SplitString_ByAnyDelimiter
REPLACE(SUBSTRING(SUBSTRING_INDEX(InputString, InputDelimiter, InputPosition),
LENGTH(SUBSTRING_INDEX(InputString, InputDelimiter, InputPosition -1)) + 1),
SELECT SplitString_ByAnyDelimiter('Anvesh Patel', ' ', 1) AS FirstName
SELECT SplitString_ByAnyDelimiter('Anvesh.Patel', '.', 2) AS LastName
SELECT SplitString_ByAnyDelimiter('Anvesh|Patel', '|', 1) AS FirstName
Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.
If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.
I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.