user2158291
user2158291

Reputation: 11

Splitting a string in SQL using MySQL

I need to take a postal code looking like:

S7Y 6H5

that's in a table and display it as

S7Y & 6H5

I can't find a command that splits the string in sql.

Upvotes: 1

Views: 101

Answers (3)

echo_Me
echo_Me

Reputation: 37243

you can use INSERT INSERT(str,pos,len,newstr)

     SELECT INSERT('S7Y 6H5', 4, 0, ' & ');

http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_insert

Upvotes: 1

www
www

Reputation: 4391

Try this:

Select REPLACE ('S7Y 6H5', ' ', ' & ')

Upvotes: 2

Jeff Ferland
Jeff Ferland

Reputation: 18312

MySQL doesn't include a split function, but it does include a replace. You could use:

SELECT REPLACE('S7Y 6HS', ' ', ' & ')

The greater question for me, though, is why don't you do that in your application code?

Upvotes: 3

Related Questions