I created an application to send mail to users. I'm using a database where some users have more than one email address assigned.
Name Mail
-----------------------------------------
BusinessXPTO mail1@xpto.com;mail2@xpto.com
The email column can contain more than one email, separated by a semicolon. I want to split the string so I can put each email on a different line.
Name Mail
-----------------------------------------
BusinessXPTO mail1@xpto.com
BusinessXPTO mail2@xpto.com
What is the best solution?
Thanks
In Oracle
Here is a mock for provided example:
Here is how to split the mail column into separate rows
Here is the result
The following is a UDF that I use to split values on an arbitrary delimiter. I've since modified my function so that it is an inline table function (instead of a multi-statement table function) and no longer relies on a Numbers table as it builds it on the fly.
Here's an example call:
Here's a simple example using the XML features in SQL Server 2005 and above. I've taken it verbatim from here but there are lots of examples if you google "split string sql server xml"
There are other solutions with cursors but this approach as worked well for me.