DELIMITER ;;
CREATE DEFINER=`root`@`localhost`
FUNCTION `StrTok`(
`in_string` VARCHAR(255),
`delims` VARCHAR(255),
`str_replace` VARCHAR(255))
RETURNS varchar(255) CHARSET utf8
NO SQL
DETERMINISTIC
BEGIN
DECLARE str_len, delim_len, a, b, is_delim INT;
DECLARE z, y VARBINARY(1);
DECLARE str_out VARBINARY(256);
SET str_len = CHAR_LENGTH(in_string);
SET delim_len = CHAR_LENGTH(delims);
SET a = 1, b = 1, is_delim = 0, str_out = '';
WHILE a <= str_len DO
SET z = SUBSTRING(in_string, a, 1);
WHILE b <= delim_len AND is_delim < 1 DO
SET y = SUBSTRING(delims, b, 1);
IF z = y THEN
SET is_delim = 1;
END IF;
SET b = b + 1;
END WHILE;
IF is_delim = 1 THEN
SET str_out = CONCAT(str_out, str_replace);
ELSE
SET str_out = CONCAT(str_out, z);
END IF;
SET b = 0;
SET is_delim = 0;
SET a = a + 1;
END WHILE;
RETURN str_out;
END ;;
DELIMITER ;
SQL Справочник v0.05 © 2007-2025 Igor Salnikov aka SunDoctor