views:

17

answers:

1

I'm creating a MySQL UDF (User Defined Function) to capitalise the first letter of every word. This is what I have so far:

drop function if exists upperfirst;
create function upperfirst (s varchar(255))
  returns varchar(255)
   deterministic
     return concat(ucase(mid(lower(s),1,1)),mid(lower(s),2));

This is working pretty well so far, except that it is only outputting the first word as uppercase, for example:

select upperfirst("abba river");/*returns "Abba river"*/

Ideally the first letter of every word should be capitalised. I'm aware of how to do this with PHP, but this is not practical for my purposes since I am trying to create a MySQL UDF.

So my question is, how could a break a string (of infinite length) into an array of words so that I can set the first character of every word to uppercase inside a MySQL function? Failing this, can anyone think of a better approach.

A: 

http://forums.mysql.com/read.php?20,265978,266040#msg-266040

Wrikken
Excellent - this worked nicely.
Aaron Newton