title: Mysql 8 custom string function always returns zero
body: <p>I'm stuck on this for a while now. I wrote a simple slugify UDF in MySQL8 that makes use of the built-in <a href="https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-replace" rel="nofollow noreferrer">regexp_replace()</a> function.</p>
  
  <p>The syntax of the function is valid, but it always returns 0 (zero), for every input.</p>
  
  <pre><code>DELIMITER $$
  CREATE FUNCTION `slugify`(dirty_string varchar(200)) RETURNS varchar(200) CHARSET utf8mb4
      DETERMINISTIC
  BEGIN
  DECLARE slug varchar(200);
  
     SET slug = REGEXP_REPLACE(LOWER(dirty_string), '[éèêë€]','e');
     SET slug = REGEXP_REPLACE(slug, '[áàâä@]','a');
     SET slug = REGEXP_REPLACE(slug, '[îï]','i');
     SET slug = REGEXP_REPLACE(slug, '[üµù]','u');
     SET slug = REGEXP_REPLACE(slug, '[öôØøº]','o');
     SET slug = REGEXP_REPLACE(slug, '[ç]','c');
     SET slug = REGEXP_REPLACE(slug, '[^a-z0-9\-]+','-');
  
  RETURN slug;
  END $$
  DELIMITER ;
  </code></pre>
  
  <p>I first suspected the special characters that may caused the trouble, but simplifying the function gives the same result:</p>
  
  <pre><code>DELIMITER $$
  CREATE FUNCTION `slugify`(dirty_string varchar(200)) RETURNS varchar(200) CHARSET utf8mb4
      DETERMINISTIC
  BEGIN
  DECLARE slug varchar(200);
  
     SET slug = REGEXP_REPLACE(LOWER(dirty_string), 'x','a');
  
  RETURN slug;
  END $$
  DELIMITER ;
  </code></pre>
  
  <p>To verify the syntax, i tried to replace the regexp_replace function with a string and that worked just fine, so the problem only occurs when regexp_replace() is assigned to a variable or return value in a custom function.</p>
  
  <p>The documentation doesn't say that you can't use regexp_replace in a udf, so why is this returning 0 without any errors or warnings?</p>