Besvarer ikke dit spørgsmål, men artiklen om MySQL udf er ret god: https://www.codeproject.com/KB/database/MySQL_UDFs.aspx