Created
June 27, 2018 13:49
-
-
Save jtarleton/92441099402a64d5e3366c1886ab20d3 to your computer and use it in GitHub Desktop.
PatIndex MySQL stored procedure
This file contains 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 DEFINER=`root`@`localhost` FUNCTION `PatIndex`(pattern VARCHAR(255), tblString VARCHAR(255)) RETURNS int(11) | |
DETERMINISTIC | |
BEGIN | |
DECLARE i INTEGER; | |
SET i = 1; | |
myloop: WHILE (i <= LENGTH(tblString)) DO | |
IF SUBSTRING(tblString, i, 1) REGEXP pattern THEN | |
RETURN(i); | |
LEAVE myloop; | |
END IF; | |
SET i = i + 1; | |
END WHILE; | |
RETURN(0); | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment