23 June, 2010

ucfirst in mysql

Its quite hard to convert first character of a string to capital in mysql. Same problem existed for me. I however managed to work it out using following sql query. This query is used to capitalize first letter of a string to upper case similar to ucfirst in php.

SELECT CONCAT(upper(substr("test this one.", 1, 1)),"", LOWER(SUBSTR("test this one.", 2, length("test this one."))));

In above query, the string "test this one." can be replaced by the field name while performing query in database.

No comments: