Skip to content

Instantly share code, notes, and snippets.

@jtarleton
Created June 27, 2018 13:49
Show Gist options
  • Save jtarleton/92441099402a64d5e3366c1886ab20d3 to your computer and use it in GitHub Desktop.
Save jtarleton/92441099402a64d5e3366c1886ab20d3 to your computer and use it in GitHub Desktop.
PatIndex MySQL stored procedure
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