Last active
July 14, 2025 21:00
-
-
Save jamalnasir/2cb9387deac373957623bfe331dc4f0f to your computer and use it in GitHub Desktop.
Get Camel Case of a String in MySQL
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
DELIMITER $$ | |
CREATE FUNCTION `camel_case`(str VARCHAR(128)) RETURNS VARCHAR(128) | |
BEGIN | |
DECLARE n, pos INT DEFAULT 1; | |
DECLARE sub, camel VARCHAR(128) DEFAULT ''; | |
DECLARE isFirstWord BOOLEAN DEFAULT TRUE; | |
IF LENGTH(TRIM(str)) > 0 THEN | |
WHILE pos > 0 DO | |
SET pos = LOCATE(' ', TRIM(str), n); | |
IF pos = 0 THEN | |
SET sub = LOWER(TRIM(SUBSTR(TRIM(str), n))); | |
ELSE | |
SET sub = LOWER(TRIM(SUBSTR(TRIM(str), n, pos - n))); | |
END IF; | |
IF isFirstWord THEN | |
SET camel = CONCAT(camel, sub); | |
SET isFirstWord = FALSE; | |
ELSE | |
SET camel = CONCAT(camel, UPPER(LEFT(sub, 1)), SUBSTR(sub, 2)); | |
END IF; | |
SET n = pos + 1; | |
END WHILE; | |
END IF; | |
RETURN camel; | |
END $$ | |
DELIMITER ; |
doesn't work, looks like you're confused between camel_case and proper_case.
return concat(lower(left(proper,1)),substr(proper,2)); instead of proper will do the trick.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks!!!!