Skip to content

Instantly share code, notes, and snippets.

@ReemRashwan
Created February 23, 2021 08:48
Show Gist options
  • Save ReemRashwan/782eda4ec4a33cf6a8cf9fa516c8bc94 to your computer and use it in GitHub Desktop.
Save ReemRashwan/782eda4ec4a33cf6a8cf9fa516c8bc94 to your computer and use it in GitHub Desktop.
ESQL: check if string contains only one unique character
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