Here is just a simple stored function to capitalize the first letter of each word in a string.
Sometimes it’is useful to convert name of cities and persons using the correct capitalization.
DROP FUNCTION IF EXISTS `capitalize`;
DELIMITER $$
CREATE FUNCTION `capitalize`(stringa TEXT) RETURNS text
DETERMINISTIC
BEGIN
DECLARE i INT DEFAULT 2;
DECLARE sout TEXT;
DECLARE ucn INT DEFAULT 0;
SET stringa=LCASE(TRIM(BOTH ' ' FROM stringa));
SET sout=UCASE(LEFT(stringa,1));
WHILE i
Example:
mysql> SELECT capitalize(' new york ');
+--------------------------+
| capitalize(' new york ') |
+--------------------------+
| New York |
+--------------------------+