Created
February 23, 2021 08:48
-
-
Save ReemRashwan/782eda4ec4a33cf6a8cf9fa516c8bc94 to your computer and use it in GitHub Desktop.
ESQL: check if string contains only one unique character
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
CREATE FUNCTION isMadeOfOneChar(IN text CHAR, IN dividerChar CHAR) RETURNS BOOLEAN | |
BEGIN | |
DECLARE index INT 1; | |
DECLARE textLength INT LENGTH(text); | |
DECLARE currentChar CHAR; | |
-- If empty string, return false | |
IF textLength = 0 THEN | |
RETURN FALSE; | |
END IF; | |
WHILE index <= textLength DO | |
SET currentChar = SUBSTRING(text FROM index FOR 1); | |
IF currentChar <> dividerChar THEN | |
RETURN FALSE; | |
END IF; | |
SET index = index + 1; | |
END WHILE; | |
RETURN TRUE; | |
END; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment