Beantwoordt je vraag niet, maar artikel over MySQL udf is best goed: https://www.codeproject.com/KB/database/MySQL_UDFs.aspx