Last active
May 16, 2018 19:50
-
-
Save NavidMitchell/989a14563e1a56f1b88bcb9f05e37710 to your computer and use it in GitHub Desktop.
MySQL First letter of each word uppercase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mysql function to make begining of word uppercase | |
// https://www.thingy-ma-jig.co.uk/blog/30-09-2010/mysql-how-upper-case-words | |
DROP FUNCTION IF EXISTS UC_DELIMETER; | |
DELIMITER // | |
CREATE FUNCTION UC_DELIMETER(oldName VARCHAR(255), delim VARCHAR(1), trimSpaces BOOL) RETURNS VARCHAR(255) | |
BEGIN | |
SET @oldString := oldName; | |
SET @newString := ""; | |
tokenLoop: LOOP | |
IF trimSpaces THEN SET @oldString := TRIM(BOTH " " FROM @oldString); END IF; | |
SET @splitPoint := LOCATE(delim, @oldString); | |
IF @splitPoint = 0 THEN | |
SET @newString := CONCAT(@newString, UC_FIRST(@oldString)); | |
LEAVE tokenLoop; | |
END IF; | |
SET @newString := CONCAT(@newString, UC_FIRST(SUBSTRING(@oldString, 1, @splitPoint))); | |
SET @oldString := SUBSTRING(@oldString, @splitPoint+1); | |
END LOOP tokenLoop; | |
RETURN @newString; | |
END// | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment