--Query the name of the corresponding row according to the ID
CREATE FUNCTIONFunction_first (IDINT)--CreateBEGIN --Start DECLARENameVARCHAR(255);--declare variables that must be written in the first line, each of which is best to write a separate declare SELECT --use SQL to query out name and assign a value to the declared variable using the INTO keywordPerson.name intoname fromPersonWHEREPerson.id=ID; IF(ISNULL(name)) Then RETURN 'No value';--return ' no value ' if not ELSE RETURNname; END IF;--End IfEND;
--A+aa+aaa...+a. A
CREATE FUNCTIONFunction_second (IDINT)--CreateBEGIN DECLAREInxnumINT DEFAULT 0; DECLAREIINT DEFAULT 0; DECLAREResultINT DEFAULT 0; Adds:loop--start a loop called adds IFI=N ThenLeave adds;--leave adds jumps out of the loop named adds END IF; SETInxnum=Inxnum+PowTenI*A; SETResult=Result+Inxnum; SETI=I+1; ENDLOOP adds;--Loop End Tag RETURNresult;END
MySQL Custom Function Example