There’s no MySQL function to do that, have to write your own. I wrote a little MySQL function to capitalize the first letter of every word in a string.
In order to use it, first, you need to create the function in the database. You can do this, for example, using MySQL Query Browser (right-click the database name and select Create new Function).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
CREATE FUNCTION CapitalizeEachWord (input VARCHAR(255)) RETURNS VARCHAR(255) DETERMINISTIC BEGIN DECLARE len INT; DECLARE i INT; SET len = CHAR_LENGTH(input); SET input = LOWER(input); SET i = 0; WHILE (i < len) DO IF (MID(input,i,1) = ' ' OR i = 0) THEN IF (i < len) THEN SET input = CONCAT( LEFT(input,i), UPPER(MID(input,i + 1,1)), RIGHT(input,len - i - 1) ); END IF; END IF; SET i = i + 1; END WHILE; RETURN input; END; |
So you can test the function by running the following SQL code…
1 2 3 |
SELECT CapitalizeEachWord( 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.' ) |
Returns the string “Lorem Ipsum Is Simply Dummy Text Of The Printing And Typesetting Industry.”
Also, you can update the values in the table with a query like this:
1 |
UPDATE users SET name = CapitalizeEachWord(name); |