Skip to content

Instantly share code, notes, and snippets.

@jonpemby
Created May 17, 2018 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonpemby/e8f105939a407eca4d2482627bc8d736 to your computer and use it in GitHub Desktop.
Save jonpemby/e8f105939a407eca4d2482627bc8d736 to your computer and use it in GitHub Desktop.
Capitalize a string in MySQL
DELIMITER $$
-- Capitalizes a word
-- @param str VARCHAR String to capitalize
-- @return VARCHAR Capitalized string
CREATE FUNCTION CAPITALIZE(str VARCHAR(255)) RETURNS VARCHAR(255)
BEGIN
RETURN CONCAT(UPPER(SUBSTRING(str, 1, 1)), SUBSTRING(str, 2));
END$$
DELIMITER ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment