MySQL Custom Function Example

Source: Internet
Author: User

--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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.