Skip to content

Instantly share code, notes, and snippets.

@fabioricali
Created November 21, 2017 16:51
Show Gist options
  • Save fabioricali/8b4ffc22c7e2de3258500f143c8bd149 to your computer and use it in GitHub Desktop.
Save fabioricali/8b4ffc22c7e2de3258500f143c8bd149 to your computer and use it in GitHub Desktop.
MYSQL capitalized
CREATE FUNCTION CAP_FIRST (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) REGEXP BINARY '[^0-9A-z]') 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment